So basically this error is appearing only when I train my model in the editor (vscode, with anaconda environment) but when i run the same script in a jupyter notebook (in vscode) it works fine no error. I think might be import error or something else. i have three files, my pytorch model, my physics model and the main train file where I do the imports.
The error is: typeError: only integer tensors of a single element can be converted to an index.
this is the line of code where the error is popping up.
noise = (torch.randn_like(action) * self.policy_noise).clamp(-self.noise_clip, self.noise_clip)
which is in the pytorch model.
here is the complete error message:
Traceback (most recent call last):
File “c:/Users/ACER/Desktop/ACER/jupyter notebook/python_scripts/drone/train.py”, line 113, in
File “c:\Users\ACER\Desktop\ACER\jupyter notebook\python_scripts\drone\agent.py”, line 144, in train
torch.randn_like(action) * self.policy_noise
TypeError: only integer tensors of a single element can be converted to an index
I guess you might be using different PyTorch versions in your IDE and Jupyter, where apparently some operations might yield different shapes.
Could you check the versions via
print(torch.__version__) and make sure they are equal?
hi thanks for answering but that is not possible im using the same virtual environment running in the IDE and jupyter. I did still checked versions via
print(torch.__verison__) and they are the same ‘1.6.0’.
@ptrblck Any other suggestion?
I also have tested the code (as a jupyte notebook) in google colab and works fine like in my local ipython. the issue is directly with the separeted scripts.
I’m not sure if I misunderstand the use case, but I thought you are using the same script and the only difference is the notebook vs. IDE?
Could you reuse the working script and execute it in the currently non-working environment, if that’s not the case?
@ptrblck yes. so what I have is 3 scripts for the IDE: agent.py(pytorch model), env.py(physics model) and train.py where I do import the other two classes. in my jupyter notebook i just have 4 cells 1 to import all the modules(torch, numpy…etc) used in the scripts, 1 cell for each script, the only output is the cumulative reward of each epoch nothing else, that is coming from the train cell.
again no error in the jupyter notebook but it does appear when i run train.py in the IDE.
something that i dont want to do but im thinking is to have just one big script, and see if the error still appear, in each script i just have one class except for the agent script which i have two classes memory buffer and the agent. it could be something related with the data, maybe somewhere i am still no changing the data format and im saving tensors instead of numpy arrays im gonna check that as well.
Yeah, it’s a bit weird, but your guess might be right. The issue might indeed come from a difference in the data loading or processing.
Could you print the shape of
action in both envs so that we could maybe try debugging the actual issue to narrow down the difference?