Getting the jacobian inside GradientTape
Les mainteneurs répondent en général sous 21 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Stack technique
- python, tensorflow
- Domaine
- machine-learning
Piste de recherche
Reproduisez le problème avec l’exemple Python fourni, en commençant par tfq.layers.PQC et l’appel à GradientTape.jacobian ; examinez l’opération TfQAdjointGradient signalée. C’est terminé lorsque le jacobien peut être calculé dans le tape tout en laissant les gradients des opérations en aval disponibles pour la mise à jour finale.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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?
- Langage dominant
- Python
- Étoiles
- 2.2k
- Forks
- 675
- Merge moyen
- 15 j 11 h
- PR mergées (30 j)
- 3
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de tensorflow/quantum
-
area/c++ area/core kind/bug-report
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
tensorflow/quantum#1140 ·
Les mainteneurs répondent en général sous 21 jours
-
area/c++ area/core kind/bug-report
Difficulté 3/5 1-2 jours Accessibilité débutants 74/100
tensorflow/quantum#1141 ·
Les mainteneurs répondent en général sous 21 jours
-
Support Keras 3Peut-être à nouveau libre @rosspeili l’a pris il y a 127 jours, et aucune pull request n’est ouverte. Ouvertearea/keras help wanted skill-level/intermediate
tensorflow/quantum#1090 · 5 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 21 jours
-
Support dynamic quantum circuitsOuvertearea/circuits priority/after-0.7.7 skill-level/expert
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
tensorflow/quantum#1087 ·
Les mainteneurs répondent en général sous 21 jours
-
Efficiently handle circuit sizes 10x or more of today's circuitsPeut-être à nouveau libre @SripriyaDevarapalli l’a pris il y a 47 jours, et aucune pull request n’est ouverte. Ouvertearea/circuits area/performance help wanted priority/after-0.7.7 skill-level/expert
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
tensorflow/quantum#1086 · 1 commentaire ·
Les mainteneurs répondent en général sous 21 jours
Toutes les issues de tensorflow/quantum
Issues similaires
-
[dbt] exported dataset keys reference physical columnsPeut-être pris @WilliamKelley l’a pris aujourd’hui. Ouverteneeds-triage
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
apache/ossie-converters#251 ·
Les mainteneurs répondent en général sous 2 jours
-
cli difficulty: easy enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
desec-io/desec-stack#1312 ·
Les mainteneurs répondent en général sous 14 jours
-
needs-triage
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
aws/aws-durable-execution-sdk-python#977 ·
Les mainteneurs répondent en général sous 1 jour
-
needs-triage
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
flashinfer-ai/flashinfer#9803 ·
Les mainteneurs répondent en général sous 1 jour