requires_grad und der Berechnungsgraph
Verfolgen Sie Operationen, um sie abzuleiten.
requires_grad und der Berechnungsgraph ist eine kostenlose Deep Learning Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Deep Learning Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Deep Learning Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
Calculus, Handled For You
Training needs derivatives, but you never compute them by hand. PyTorch's autograd watches your math and works out every gradient for you. 🤖
Tensors Can Track Themselves
A tensor only earns gradients when you ask. Set requires_grad to true and PyTorch starts recording every operation done to it.
x = torch.tensor(2.0, requires_grad=True)What Gets Recorded
Each math step on a tracked tensor is logged as a node. Together these nodes form a computation graph describing how your result was built.
The Graph Is a Recipe
Think of the graph as a recipe: inputs at the top, operations in the middle, your final loss at the bottom. Autograd reads it backward to find gradients.
Built On the Fly
PyTorch uses a dynamic graph: it is created as your code runs, not ahead of time. Normal Python loops and ifs just work inside it.
Results Stay Connected
Any tensor made from a tracked one is also tracked. Here y remembers it came from x, so its grad_fn points back to that squaring step.
y = x ** 2
print(y.grad_fn)Leaves vs Computed Nodes
Tensors you create directly are leaf nodes. Tensors produced by operations are interior nodes that link back toward those leaves.
grad_fn Names the Step
Every computed tensor carries a grad_fn telling autograd which operation made it, like PowBackward or AddBackward. Leaves have no grad_fn.
No Tracking, No Graph
If a tensor has requires_grad false, autograd ignores it and builds no graph. That saves memory whenever you do not need gradients.
Why the Graph Matters
The graph is what makes the backward pass possible. Without this recorded history, PyTorch would have no way to know how the loss depends on each weight.
You Just Write Forward
The beauty is you only code the forward math. Autograd silently assembles the graph so the gradients are ready the moment you ask for them.
Quick Check
Recap
Set requires_grad and PyTorch records your math into a computation graph. That recorded history is what autograd later reads backward to find every gradient. ✨
Häufig gestellte Fragen
Ist die Lektion „requires_grad und der Berechnungsgraph“ kostenlos?
Ja — der vollständige Text von „requires_grad und der Berechnungsgraph“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Deep Learning Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Deep Learning Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „requires_grad und der Berechnungsgraph“?
Verfolgen Sie Operationen, um sie abzuleiten. Du übst Deep Learning Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Deep Learning Academy zu starten?
Keine Vorkenntnisse erforderlich. Deep Learning Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.
Wie lange dauert die Lektion „requires_grad und der Berechnungsgraph“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Deep Learning Academy-Lektion Code schreiben und ausführen?
Ja. Jede Deep Learning Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- requires_grad und der Berechnungsgraph
- Mit backward() Gradienten berechnen
- .grad auslesen und auf null setzen
- torch.no_grad() für Inferenz