Closed chm5174 closed 5 years ago
Hi @chm5174,
which line of code throws this warning?
Is it an internal apex
method or does this warning come from your custom Function
?
Thank you for your reply. I am running my test on pycharm and it only raised a warning,
/opt/conda/condabld/pytorch_1565287148058/work/torch/csrc/autograd/python_function.cpp:638: UserWarning: Legacy autograd function with non-static forward method is deprecated and will be removed in 1.3. Please use new-style autograd function with static forward method. (Example: https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function)
but didn't prompt which line of my code was wrong. In addition, my code didn't run out of results.
@chm5174 i meet this too, are you get the answer??? my code is work, but raise many warning like that, i cant figure it out...
my setting: Pytorch1.2 Apex 1.0 Cuda 10.1
Hi @chm5174,
which line of code throws this warning? Is it an internal
apex
method or does this warning come from your customFunction
?
it comes form the custom 'Fuction' as follow:
class GradReverse(Function):
def __init__(self, lambd):
self.lambd = lambd
def forward(self, x):
return x.view_as(x)
def backward(self, grad_output):
return -self.lambd * grad_output
when we backward our loss, the UserWarning comes out
^ That definitely has nothing to do with Apex. You need to apply the @staticmethod
decorator to your forward and backward functions. I believe all custom autograd functions in Apex have already done so.
Please reopen if you find that adding Apex causes new warnings to appear.
Hi, I’m having trouble when running my test.
A UserWarning was added to pytorch: "Legacy autograd function with non-static forward method is deprecated and will be removed in 1.3. ","Please use new-style autograd function withstatic forward method.","(Example: https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function)".
I found the solution Update to new PyTorch Function API ("Legacy autograd function with non-static forward method is deprecated") #401 through Google and installed the whole Nvidia/apex accoding to the instructions.
I executed the follwoing commands for installing the apex:
pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./
Here’s the full log:
` Created temporary directory: /tmp/pip-record-ltooag15 Running command /root/anaconda3/envs/pytorch/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-qv8b50ca/setup.py'"'"'; file='"'"'/tmp/pip-req-build-qv8b50ca/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' --cpp_ext --cuda_ext install --record /tmp/pip-record-ltooag15/install-record.txt --single-version-externally-managed --compile torch.version = 1.2.0 /tmp/pip-req-build-qv8b50ca/setup.py:33: UserWarning: Option --pyprof not specified. Not installing PyProf dependencies! warnings.warn("Option --pyprof not specified. Not installing PyProf dependencies!")
Running setup.py install for apex ... done Removing source in /tmp/pip-req-build-qv8b50ca Successfully installed apex-0.1 Cleaning up... Removed build tracker '/tmp/pip-req-tracker-f0xk6je4' 1 location(s) to search for versions of pip:
It seems that the installation was successful through Successfully installed apex-0.1 but it didn’t work, the test still goes wrong and a warning appears:/opt/conda/condabld/pytorch_1565287148058/work/torch/csrc/autograd/python_function.cpp:638: UserWarning: Legacy autograd function with non-static forward method is deprecated and will be removed in 1.3. Please use new-style autograd function with static forward method. (Example: https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function)
Is it where I am not doing it properly? Could you please help me? Thanks a lot!