💡 [REQUEST] - Clarification of requires_grad about beginner/nn_tutorial.html

Abierto
#3,716 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

  • #3717 de @FlightVin — cerrado sin fusionar

Evaluación

Dificultad
1/5
Tiempo estimado
Menos de una hora
Aptitud para principiantes
55/100
Tipo de issue
Documentación
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
python, pytorch

Línea de trabajo

Abre el código fuente de beginner/nn_tutorial.html y localiza la sección “Neural Net from Scratch without torch.nn”. Actualiza el comentario existente sobre los pesos y el bias para explicar por qué requires_grad se difiere para los pesos después de los cálculos de inicialización; se considera terminado cuando la distinción entre tensores leaf y non-leaf quede clara en el tutorial renderizado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

🚀 Describe the improvement or the new tutorial

It was challenging for me to initially grasp why requires_grad was done after weights, but in the same line as bias under https://docs.pytorch.org/tutorials/beginner/nn_tutorial.html#neural-net-from-scratch-without-torch-nn

At first glance, the code looks inconsistent:

  1. weights initialization is split into two lines.
  2. bias initialization is done in one line.

The Logic Gap
The tutorial currently explains that we do it, but not exactly why the distinction exists between these two specific variables.

  • The Bias is created using a factory function (torch.zeros) with no subsequent mathematical operations. It is born as a "Leaf Node" (a source parameter).
  • The Weights involve a mathematical operation (/ math.sqrt(...)). If we set requires_grad=True inside torch.randn(), PyTorch records the division as a computational step. The resulting weights variable becomes a non-leaf node (a calculated outcome), which the optimizer cannot update.

Proposed Improvement
I propose modifying the comment block to explicitly mention that requires_grad must be deferred until after the initialization math is complete to preserve the tensor as a trainable parameter (Leaf Node).

Existing tutorials on this topic
Additional context
Image
Lenguaje dominante
Python
Estrellas
9.5k
Forks
4.5k
Merge medio
1 d 20 h
PR fusionados (30 d)
2

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pytorch/tutorials

Todos los issues de pytorch/tutorials

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.