Skip to content

Commit 1e1ea0a

Browse files
Merge branch 'master' into beta
2 parents 49106eb + c666578 commit 1e1ea0a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
- Fix adjoint gate numpy conversion for fixed gate case
2424

25+
- Sometime, tf just return IndexedSlice instead of tensor from gradient API, partially fix this in tc backend methods
26+
2527
### Changed
2628

2729
- Upgraded black and mypy==1.2.0 (breaking change for developers)

tensorcircuit/backends/tensorflow_backend.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,11 @@ def vjp(
725725
for i, gi in enumerate(g):
726726
if gi is None:
727727
g[i] = tf.zeros_like(inputs[i])
728+
if isinstance(gi, tf.IndexedSlices):
729+
# gradient can return sth weird
730+
# TODO(@refraction-ray): check whether other AD tf methods have such issues
731+
# shape is still unkown, dense_shape attr doesn't work?
732+
g[i] = tf.convert_to_tensor(gi)
728733
g = tuple(g)
729734
if one_input:
730735
g = g[0]

0 commit comments

Comments
 (0)