PyTorch Tutorial 03 - Gradient Calculation With Autograd

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ธ.ค. 2024

ความคิดเห็น • 97

  • @simonbernard4216
    @simonbernard4216 4 ปีที่แล้ว +29

    I appreciate that you followed the official tutorial from the Pytorch documentation. Also your comments make things much clearer

    • @patloeber
      @patloeber  4 ปีที่แล้ว +2

      Thanks! Glad you like it

  • @shazinhotech2155
    @shazinhotech2155 2 ปีที่แล้ว +2

    what an amazing teacher you are

  • @DanielWeikert
    @DanielWeikert 5 ปีที่แล้ว +40

    This is great work. I really like the detailed explanation using simple practical examples. Please continue doing this exploring the various options in pytorch. Happy holidays

    • @patloeber
      @patloeber  5 ปีที่แล้ว +3

      Thank you! Glad you like it. I have more videos planned for the next few days :) Happy holidays!

  • @EnuCan
    @EnuCan 5 หลายเดือนก่อน +1

    Simply amazing, Appreciate your efforts and making it available to the public :)

  • @GurpreetSingh-si2gh
    @GurpreetSingh-si2gh 2 ปีที่แล้ว +3

    I appreciate your efforts, you readily explained every detail. Thanks very much.
    🙏

  • @dataaholic
    @dataaholic 4 ปีที่แล้ว +12

    @ 8:00 what is the difference between z.backward() vs z.backward(v)?
    z.backward() ==> is calculating dz/dx
    is z.backward(v) ==> is calculating dz/dv ?

    • @alanzhu7538
      @alanzhu7538 3 ปีที่แล้ว +5

      Also, how do we decide the value for v?

    • @gautame
      @gautame 3 ปีที่แล้ว +1

      z.backward(v) calculates dz/dx*v

    • @peixinwu4631
      @peixinwu4631 2 ปีที่แล้ว

      @@alanzhu7538 You got any idea now?😂

    • @peixinwu4631
      @peixinwu4631 2 ปีที่แล้ว

      @@gautame You mean v * (dz/dx)? Or dz/(dx * v)?

    • @faseehahmed6164
      @faseehahmed6164 2 ปีที่แล้ว

      @@peixinwu4631 v * (dz/dx)

  • @王灵玄
    @王灵玄 3 ปีที่แล้ว +5

    This tutorial is brilliant. It is super friendly to people who are new to Pytorch!

    • @patloeber
      @patloeber  3 ปีที่แล้ว

      glad you like it!

  • @nishaqiao828
    @nishaqiao828 4 ปีที่แล้ว +3

    Thank you! Your video helps a lot to my undergraduate final project!

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      that's nice to hear :)

  • @barbaraulitsky8292
    @barbaraulitsky8292 ปีที่แล้ว +2

    This video is super helpful! Explanations are very understandable. Thank you so much!!🤩👍🙏

  • @Murmur1131
    @Murmur1131 3 ปีที่แล้ว +1

    @ 8:16 do you have a simple real life "example" why we have to use the v for the right size and why it wouldn't work without it? I know silly question, but I don't really grasp the concept behind it..

  • @mihaidumitrescu1325
    @mihaidumitrescu1325 8 หลายเดือนก่อน

    Fantastic work!
    slight recommendation of how to improve this: if u use the same naming scheme in the Jacobian and in the code (l vs z), we can follow easier the chain rule!

  • @exxzxxe
    @exxzxxe 4 ปีที่แล้ว +2

    Very well done. An excellent video!

  • @yishu4244
    @yishu4244 3 ปีที่แล้ว

    This video helps me greatly. I like your language speed since English is not my mother tongue. Thank you a lot.

    • @patloeber
      @patloeber  3 ปีที่แล้ว

      Nice, glad you like it

  • @marcoantonioarmentaarmenta1350
    @marcoantonioarmentaarmenta1350 4 ปีที่แล้ว +2

    This video is extremely useful. Thank you!

  • @henrygory
    @henrygory ปีที่แล้ว

    Excellent video. Thanks!

  • @warrior_1309
    @warrior_1309 2 ปีที่แล้ว

    Great Work Sir.

  • @kevinw6237
    @kevinw6237 2 ปีที่แล้ว

    This video is very clear in explaining things. Thank you so much sir! Keep up the good work pls!

  • @秦默雷
    @秦默雷 2 ปีที่แล้ว

    This tutorial is more than great! Thank you!

  • @andywang4189
    @andywang4189 10 หลายเดือนก่อน

    Very clear, thank you very much

  • @popamaji
    @popamaji 4 ปีที่แล้ว +3

    interesting thing that I realized is that eventhough after set z=z.mean which changes grad_fn of z from mulbackward to meanbackward(so z doesnt have mulbackward anymore), it is still able to track gradient

    • @patloeber
      @patloeber  4 ปีที่แล้ว +2

      if requires_grad=true, any operation that we do with z tracks the gradient

  • @haroldsu1696
    @haroldsu1696 2 ปีที่แล้ว

    Great work Sir, and Thank you!

  • @consistentthoughts826
    @consistentthoughts826 3 ปีที่แล้ว +1

    @5:46 in the image it is J^T . V

  • @maithilijoshi796
    @maithilijoshi796 ปีที่แล้ว

    thankyou for your efforts

  • @danielpietschmann5294
    @danielpietschmann5294 4 ปีที่แล้ว +7

    why can you just specify v as [0.1, 1.0, 0.001], why not some other numbers?

    • @crivatz
      @crivatz ปีที่แล้ว

      Did you find out?

    • @minister1005
      @minister1005 ปีที่แล้ว

      It doesn't matter. You just need to have the same shape

  • @my_opiniondemocracy6584
    @my_opiniondemocracy6584 2 ปีที่แล้ว +4

    how did you decide values in vector v?

    • @luanmartins8068
      @luanmartins8068 7 หลายเดือนก่อน

      The gradient in 5:46 is the multiplication of the jacobian matrix and a directional vector. When the function which you want to calculate the gradient has a one dimensional output, there is no need to determine a direction for derivative since it is unique, that's why for the mean gradient it accepts no arguments. On other hand, see that for a multidimensional output as x+2 = y (y is a multidimensional output, a vector), you have to specify what direction you want to take your gradient. That is where the v vector enters. He arbitrarily choose components just to show that the function requires an vector to define the directional derivative, but usually for statistical learning it is chosen the direction where the gradient is steepest

  • @cypherecon5989
    @cypherecon5989 7 หลายเดือนก่อน

    I don't get why you need the 3 methods presented at 8:06 for preventing the gradient. Can one not simply put requires_grad=False in the x tensor?

  • @wiktormigaszewski8684
    @wiktormigaszewski8684 5 ปีที่แล้ว +1

    very nice, congrats!

  • @DiegoAndresAlvarezMarin
    @DiegoAndresAlvarezMarin 3 ปีที่แล้ว +2

    Thank you very much for your tutorial. However, I did not plenty understand some details, like the variable v or the use of the optimizer.

  • @gordonxie7173
    @gordonxie7173 3 ปีที่แล้ว

    Great work!

  • @foodsscenes5891
    @foodsscenes5891 4 ปีที่แล้ว

    Quite love these courses! Great thanks

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      Thank you :)

  • @dfdiasbr
    @dfdiasbr 9 หลายเดือนก่อน

    awesome! Thank you

  • @bhomiktakhar8226
    @bhomiktakhar8226 3 ปีที่แล้ว

    Just on to my 4 lec in pytorch series. Don't know if it's a complete series on pytorch ,but definitely whatever is there it's depicted nicely.

    • @patloeber
      @patloeber  3 ปีที่แล้ว

      nice, yes it's a complete beginner series

  • @13579Josiah
    @13579Josiah 3 ปีที่แล้ว

    At 9:30, isn’t another way to do x.volatile = False ?

  • @sanjaykrish8719
    @sanjaykrish8719 3 ปีที่แล้ว

    All in one pytorch.. yeahhh.. fantastic.. thanks a ton🎉🎊🎊

    • @patloeber
      @patloeber  3 ปีที่แล้ว

      glad you like it!

  • @samirelamrany5323
    @samirelamrany5323 ปีที่แล้ว

    great work thank you

  • @alexandredamiao1365
    @alexandredamiao1365 4 ปีที่แล้ว

    Great tutorial! Thanks for this material!

  • @charithas90
    @charithas90 3 ปีที่แล้ว

    very nice tutorial. thank you!

  • @iposipos9342
    @iposipos9342 4 ปีที่แล้ว +2

    Thanks for the video. for the tensor v, are the values of any importance or its only the size that is of importance?

    • @patloeber
      @patloeber  4 ปีที่แล้ว +2

      Hi, good question! Yes this can be a bit confusion, so I provided some links from the pytorch forum which might help:
      discuss.pytorch.org/t/how-to-use-torch-autograd-backward-when-variables-are-non-scalar/4191/4
      discuss.pytorch.org/t/clarification-using-backward-on-non-scalars/1059

    • @sebimoe
      @sebimoe 4 ปีที่แล้ว +1

      @@patloeber I can't find anyone describe how to use it there, are you able to give a quick summary? Help much be appreciated as I can't find anything, including values 0.1, 1, 0.001

    • @jesuispac
      @jesuispac 4 ปีที่แล้ว +1

      @@sebimoe Apparently he doesn't know either....Typical

    • @priyanka5516
      @priyanka5516 4 ปีที่แล้ว

      In my understanding, only the size will matter. So you can write v=torch.randn(3). Then pass v in backward function.

    • @dataaholic
      @dataaholic 4 ปีที่แล้ว

      Did anyone find a good explanation for v ? I'm also bit confused here
      @ 8:00 what is the difference between z.backward() vs z.backward(v)?
      z.backward() ==> is calculating dz/dx
      is z.backward(v) ==> is calculating dz/dv ?

  • @soumyajitsarkar2372
    @soumyajitsarkar2372 4 ปีที่แล้ว +3

    Really amazing and very well explained ! Thank You .
    Btw what IDE are you using ? looks so cool and handy , love the output option below .

  • @anurajms
    @anurajms ปีที่แล้ว

    thank you

  • @milk_steak_the_original
    @milk_steak_the_original 3 ปีที่แล้ว

    When do you learn the why of things ? why am I making a gradient ? when would I use it ? I feel like these things are often explained in DS videos/classes

  • @alejandrosaenz4551
    @alejandrosaenz4551 4 ปีที่แล้ว +2

    I just discoverd your channel and it's really good! One question, I dont totally understand why we should use .detach() or no_grad() when updating weights... we are creating a new graph or something like that? what "prevent to tracking the gradient" exactly means? Hope you can help me with that. Keep the good job (:

    • @patloeber
      @patloeber  4 ปีที่แล้ว +11

      You should use this for example after the training when you evaluate your model. Because otherwise for each operation you do with your tensor, PyTorch will calculate the gradients. This is time consuming and expensive, so we don't want this anymore after the training because we no longer need backpropagation. It will reduce memory usage and speed up computations.

  • @xkaline
    @xkaline 3 ปีที่แล้ว

    Great PyTorch Tutorial videos! May I know what is the VS Code extension you use to autocomplete the PyTorch line?

    • @patloeber
      @patloeber  3 ปีที่แล้ว

      In this video it was only the built-in autocompletion through the official Python extension

  • @Muhammad_Abdullah_Sultan
    @Muhammad_Abdullah_Sultan 7 หลายเดือนก่อน

    Amazing

  • @taku8751
    @taku8751 4 ปีที่แล้ว +1

    Really good tutorial, but I wanna know what the app which you use to draw is.

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      I used an Ipad for this (some random notes app)

  • @jorgemercadog
    @jorgemercadog 3 ปีที่แล้ว

    Thank you!!

    • @patloeber
      @patloeber  3 ปีที่แล้ว

      thanks for watching

  • @mahdiamrollahi8456
    @mahdiamrollahi8456 2 ปีที่แล้ว

    If i want to play with it, suppose that we have y=3x, and we should get the answer of 3 for the gradient. So, how can i do that in pytorch?

  • @lowkeyretro7
    @lowkeyretro7 ปีที่แล้ว

    Getting this error,
    RuntimeError: Trying to backward through the graph a second time (or directly access saved tensors after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved tensors after calling backward.

  • @andrei642
    @andrei642 2 ปีที่แล้ว +2

    I had a german professor who also pronounced "value" as "ualue". Can you explain why do you sometimes pronounce it that way? I am very intrigued.
    P.S. you have the best pytorch series on youtube

  • @yuyangxi3359
    @yuyangxi3359 4 ปีที่แล้ว

    pretty good

  • @RenweiDeng
    @RenweiDeng ปีที่แล้ว

    This is so f**king useful, thank you sooo much!!

  • @МихаилПоликарпов-ф4м
    @МихаилПоликарпов-ф4м 4 ปีที่แล้ว

    I cant understand,why must gradient equal +gradient (gradient=+gradient) in each epoch.Where Can I find consistent mathematic formula?Can you explain me once?

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      I'm not exactly sure what you mean. Can you point me to the time in the video where I show this?

  • @chq7759
    @chq7759 3 ปีที่แล้ว +2

    When I run the following code, I encountered an error. Could you help me? Thank you very much!
    weights = torch.ones(4, requires_grad=True)
    optimizer = torch.optim.SGD(weights, lr=0.01)
    The error is
    Traceback (most recent call last):
    File "D:/1pytorch-tutorial/my_try/learning-PythonEngineer/learning.py", line 113, in
    optimizer = torch.optim.SGD(weights, lr=0.01)
    File "D:\Anaconda3\lib\site-packages\torch\optim\sgd.py", line 68, in __init__
    super(SGD, self).__init__(params, defaults)
    File "D:\Anaconda3\lib\site-packages\torch\optim\optimizer.py", line 39, in __init__
    torch.typename(params))
    TypeError: params argument given to the optimizer should be an iterable of Tensors or dicts, but got torch.FloatTensor

    • @LeonardoRocha0
      @LeonardoRocha0 2 ปีที่แล้ว

      torch.optim.SGD([weights], lr=0.01)

  • @oleholgerson3416
    @oleholgerson3416 4 ปีที่แล้ว +1

    That’s good, ja? :)

  • @saurabhkumar-wj1nz
    @saurabhkumar-wj1nz 4 ปีที่แล้ว

    Hey, could you explain what it means by tracking the gradient. I mean why its a issue??

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      Tracking each operation is necessary for the backpropagation. But it is expensive, so after the training we should disable it

  • @my_opiniondemocracy6584
    @my_opiniondemocracy6584 2 ปีที่แล้ว

    in the end...it became heavy

  • @filosofiadetalhista
    @filosofiadetalhista ปีที่แล้ว

    I'm not sure how you managed to be unclear on the third video of the series.
    What you said about gradients, .backwards(), .step(), and .zero_grad() were not clear at all.

  • @mittalmayankcool
    @mittalmayankcool ปีที่แล้ว

    Too many advertisements

  • @suecheng3755
    @suecheng3755 ปีที่แล้ว

    Great work!