Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

autograd sample code contains wrong logic and wrong answer #1

Open
@chhotii-alex

Description

Code sample in this section: https://github.com/Devinterview-io/pytorch-interview-questions?tab=readme-ov-file#code-example-autograd-in-action

x.grad is the partial derivative of w with respect to x, which is $\frac{\partial{w}}{\partial{z}}$ $\frac{\partial{z}}{\partial{x}}$
$\frac{\partial{w}}{\partial{z}}$ = 2ドルx$
$\frac{\partial{z}}{\partial{x}}$ = $y$
Thus $\frac{\partial{w}}{\partial{z}}$ $\frac{\partial{z}}{\partial{x}}$ = 2ドルzy$. $y$ was initialized to 4, and $z$ = $xy$ = 12. So 2ドルzy$ = 2 times 12 times 4 = 96.

Likewise you can work out the value of y.grad using the chain rule as well, and it's 72.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /