Getting the jacobian inside GradientTape
Maintainer antworten meist innerhalb von 21 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- python, tensorflow
- Bereich
- machine-learning
Rechercherichtung
Reproduziere das Problem mit dem bereitgestellten Python-Beispiel, beginnend bei tfq.layers.PQC und dem Aufruf von GradientTape.jacobian; untersuche die gemeldete TfQAdjointGradient-Operation. Als abgeschlossen gilt die Aufgabe, wenn die Jacobi-Matrix innerhalb des Tapes berechnet werden kann und die Gradienten aus nachgelagerten Operationen für das abschließende Update weiterhin verfügbar sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
If I want to compute the jacobian inside of gradient tape (so I can use it downstream in optimization) classically I can do:
x = tf.random.normal([7, 1])
model = tf.keras.Sequential([
tf.keras.layers.Input(shape=(1,)),
tf.keras.layers.Dense(5),
])
with tf.GradientTape(persistent=True) as tape:
y = model(x)
j = tape.jacobian(y, model.trainable_variables[0])
But if I try to do that with a PQC in the mode, I get the following error: LookupError: No gradient defined for operation'TfqAdjointGradient' (op type: TfqAdjointGradient). In general every operation must have an associated `@tf.RegisterGradient` for correct autodiff, which this op is lacking. If you want to pretend this operation is a constant in your program, you may insert `tf.stop_gradient`. This can be useful to silence the error in cases where you know gradients are not needed, e.g. the forward pass of tf.custom_gradient. Please see more details in https://www.tensorflow.org/api_docs/python/tf/custom_gradient.
Example code:
x = tfq.convert_to_tensor([cirq.Circuit()] * 7)
qubits = cirq.GridQubit.rect(1, 2)
readouts = [cirq.Z(i) for i in qubits]
s = sympy.symbols("a b")
c = cirq.Circuit()
c += cirq.ry(s[0]).on(qubits[0])
c += cirq.ry(s[1]).on(qubits[1])
model = tf.keras.Sequential([
tf.keras.layers.Input(shape=(), dtype=tf.string),
tfq.layers.PQC(c, readouts),
])
with tf.GradientTape(persistent=True) as tape:
y = model(x)
j = tape.jacobian(y, model.trainable_variables[0])
If I put in a tf.stop_gradient(y) then I just get the jacobian to be none. Also I don't want to use a stop gradient because there are down stream tasks I want the gradient accumulating through for a final GD update. Is this is a known limitation or am I doing something wrong? In either case, what would your recommended path forward be?
- Vorherrschende Sprache
- Python
- Sterne
- 2.2k
- Forks
- 675
- Ø Merge
- 15 T. 11 Std.
- Gemergte PRs (30 T.)
- 3
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus tensorflow/quantum
-
area/c++ area/core kind/bug-report
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
tensorflow/quantum#1140 ·
Maintainer antworten meist innerhalb von 21 Tagen
-
area/c++ area/core kind/bug-report
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 74/100
tensorflow/quantum#1141 ·
Maintainer antworten meist innerhalb von 21 Tagen
-
Support Keras 3Evtl. wieder frei @rosspeili hat das vor 127 Tagen übernommen, und es ist kein Pull Request offen. Offenarea/keras help wanted skill-level/intermediate
tensorflow/quantum#1090 · 5 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 21 Tagen
-
area/circuits priority/after-0.7.7 skill-level/expert
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
tensorflow/quantum#1087 ·
Maintainer antworten meist innerhalb von 21 Tagen
-
Efficiently handle circuit sizes 10x or more of today's circuitsEvtl. wieder frei @SripriyaDevarapalli hat das vor 47 Tagen übernommen, und es ist kein Pull Request offen. Offenarea/circuits area/performance help wanted priority/after-0.7.7 skill-level/expert
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
tensorflow/quantum#1086 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 21 Tagen
Alle Issues in tensorflow/quantum
Ähnliche Issues
-
[dbt] exported dataset keys reference physical columnsEvtl. vergeben @WilliamKelley hat das heute übernommen. Offenneeds-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
apache/ossie-converters#251 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
cli difficulty: easy enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
desec-io/desec-stack#1312 ·
Maintainer antworten meist innerhalb von 14 Tagen
-
needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
aws/aws-durable-execution-sdk-python#977 ·
Maintainer antworten meist innerhalb von 1 Tag
-
needs-triage
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
flashinfer-ai/flashinfer#9803 ·
Maintainer antworten meist innerhalb von 1 Tag