Objectorientedprogramming in pytorch

username: km_proton
cooked: <p>i recently learned oops and i am wondering what is utils.data.dataloader is could anyone please tell me structure of code like what is class here and what is function here and what is module here</p>

username: albanD
cooked: <p>Hi,</p>
<p>I am not sure to understand your question fully.<br>
But in general in pytorch, we use capital letters for classes and lower case for regular functions. Does that answer your question?</p>

username: km_proton
cooked: <p>firstofall i am sorry for wasting your precious time my doubt is i dont understand the working of pytorch. could you please tell me what happens when i type import torch (i belive a file called torch would be acessible to use in code). if my assumption is true then what does utils.data.dataloader does . i get the point that dataloader() is a function then what are utils and data representing are these representing classes or something like that. to be precise my question is regarding structure of the command <strong>torch.utils.data.dataloader()</strong>  what are we accessing (could you please tell me like you are accessing <strong>module&gt;&gt;file&gt;&gt;class&gt;&gt;function</strong>) i am asking about the structure what is class here what is module here what is file here of course i can understand dataloader is function but what are data and utils. hope i made my doubt clear</p>

username: km_proton
cooked: <p>is it that torch.tensor tensor function is present in <strong>init</strong> file<br>
so that torch is module utils is file data is class and dataloader is class<br>
in official docs there is no word about oops part</p>

username: albanD
cooked: <p>Hi,</p>
<p>For <code>torch.utils.data.DataLoader</code>, <code>torch</code>, <code>utils</code>, <code>data</code> are modules. And <code>DataLoader</code> is a class define in the <code>data</code> module.<br>
You might want to find a course on python to understand these things better.</p>

username: km_proton
cooked: <p>ok i get it but non of the courses i learnt told me that you can call a class. i mean they taught me only functions can be called . can classes be called then what component in classes are we calling is it that we are passing arguments using brackets(ie class(argument1,argument2)) and we are useing these arguments to get values for processing i mean if we call a function it returns a value but if we call a class what does it return (a value?)</p>

username: albanD
cooked: <p>When you do <code>dataloader = torch.utils.data.DataLoader(args)</code>. Then you create a new instance of the class <code>DataLoader</code>. This calls the <code>__init__()</code> function defined for that class.<br>
Now if you call the instance <code>dataloader()</code>, then it will call the <code>__call__()</code> method on the class.</p>
<p>You can simply override that method to make your class instance callable.</p>

username: km_proton
cooked: <p><a class="mention" href="/u/alband">@albanD</a> sorry if i am disturbing you .  i would like to ask you one question<br>
1.if i import torch then if there is a file called tensor.py which contains the (assume) class tensor1 then if i need to call the class tensor1 is it enough to call tensor1() or should i call tensor.tensor1</p>

username: albanD
cooked: <p>When you <code>import torch</code>. It will look for the <code>__init__.py</code> file in the <code>torch/</code> folder (local folder or in the install directories of python).</p>
<p>For calling things inside a python module, it will depend how you import it. But here again you will get a much better idea by reading about python modules directly to get a better sense of what is happening.</p>

username: km_proton
cooked: <p><a class="mention" href="/u/alband">@albanD</a>  ok as of now does is thinking pytorch omits file and only takes only directories and classes makes sense right? . can i imagine like if you use import then classes in all files (.py files) present in that directory gets copied to <strong>init</strong></p>

username: albanD
cooked: <p>Hi,</p>
<p>I’m sorry I don’t understand your question <img src="https://discuss.pytorch.org/images/emoji/apple/confused.png?v=9" title=":confused:" class="emoji" alt=":confused:"><br>
Note that pytorch is doing nothing special here. It just uses python constructs and is built like any other python package.</p>

username: km_proton
cooked: <p><a class="mention" href="/u/alband">@albanD</a>  i got it  a user called chetan answered me however thanks a lot for the help and time<br>
my question was actually that python ignores file in path ie if a class is inside<br>
pkg1-subpkg1-file.py-class then to acess it pkg1.subpkg1.class() it omits file</p>

username: km_proton
cooked: <p>could you please answer this question</p><aside class="quote" data-post="1" data-topic="82184">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/k/7ab992/48.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/use-of-backward/82184">Use of .backward()</a> 
  </div>
  <blockquote>
    what is the use of backward i cannot understand 
x=torch.tensor(3.,requires_grad=True) 
w=torch.tensor(2.,requires_grad=True) 
b=torch.tensor(4.,requires_grad=True) 
y=w*x+b 
y.backward() 
x.grad 
w.grad 
b.grad 
could you please explain use of .backward class also use of .grad
  </blockquote>
</aside>