From 5a463d1ced6d41c1489428b2c9741ef9df942b12 Mon Sep 17 00:00:00 2001
From: Denisa Roberts <denisa.roberts@denisaroberts.me>
Date: Sat, 26 Sep 2020 13:47:02 -0400
Subject: [PATCH] Add reference pdf to qr backward and add assumptions to docs

---
 tensorflow/core/api_def/base_api/api_def_Qr.pbtxt | 4 ++++
 tensorflow/python/ops/linalg_grad.py              | 1 +
 2 files changed, 5 insertions(+)

diff --git a/tensorflow/core/api_def/base_api/api_def_Qr.pbtxt b/tensorflow/core/api_def/base_api/api_def_Qr.pbtxt
index ac8f7597aae..3d8fbea9424 100644
--- a/tensorflow/core/api_def/base_api/api_def_Qr.pbtxt
+++ b/tensorflow/core/api_def/base_api/api_def_Qr.pbtxt
@@ -34,6 +34,10 @@ END
 Computes the QR decomposition of each inner matrix in `tensor` such that
 `tensor[..., :, :] = q[..., :, :] * r[..., :,:])`
 
+Currently, the gradient for the QR decomposition is well-defined only when
+the first `P` columns of the inner matrix are linearly independent, where
+`P` is the minimum of `M` and `N`, the 2 inner-most dimmensions of `tensor`.
+
 ```python
 # a is a tensor.
 # q is a tensor of orthonormal matrices.
diff --git a/tensorflow/python/ops/linalg_grad.py b/tensorflow/python/ops/linalg_grad.py
index 40f03491e6d..847d144bde3 100644
--- a/tensorflow/python/ops/linalg_grad.py
+++ b/tensorflow/python/ops/linalg_grad.py
@@ -524,6 +524,7 @@ def _QrGrad(op, dq, dr):
     return _QrGradSquareAndDeepMatrices(q, r, dq, dr)
 
   # Partition a = [x, y], r = [u, v] and reduce to the square case
+  # The methodology is explained in detail in https://arxiv.org/abs/2009.10071
   a = op.inputs[0]
   y = a[..., :, num_rows:]
   u = r[..., :, :num_rows]