Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tensors does not require grad and does not have a grad_fn #16

Closed
khelkun opened this issue May 22, 2023 · 1 comment
Closed

tensors does not require grad and does not have a grad_fn #16

khelkun opened this issue May 22, 2023 · 1 comment

Comments

@khelkun
Copy link

khelkun commented May 22, 2023

Thanks for your work @MoyGcc and sorry to bother you because my pytorch and deep learning knowledge is quite basic.

After running into some issues details in #13, I'm now able to run train.py. It's now around epoch 700 and I wonder if I'm supposed to let it run until the max epochs defined in train.py e.g 8000 ?

However I tried to run test.py with this trained model at epoch 700. But it complains about element 0 of tensors does not require grad and does not have a grad_fn with the following output:

/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/pytorch_lightning/trainer/connectors/accelerator_connector.py:479: LightningDeprecationWarning: Setting `Trainer(gpus=1)` is deprecated in v1.7 and will be removed in v2.0. Please use `Trainer(accelerator='gpu', devices=1)` instead.
  f"Setting `Trainer(gpus={gpus!r})` is deprecated in v1.7 and will be removed"
GPU available: True (cuda), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
Restoring states from the checkpoint path at checkpoints/last.ckpt
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
Loaded model weights from checkpoint at checkpoints/last.ckpt
Testing DataLoader 0:   0%|                                                                                                                                                     | 0/42 [00:00<?, ?it/s]/home/vizua/vid2avatar/code/v2a_model.py:219: UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
  1) // pixel_per_batch
/home/vizua/vid2avatar/code/lib/utils/meshing.py:49: FutureWarning: marching_cubes_lewiner is deprecated in favor of marching_cubes. marching_cubes_lewiner will be removed in version 0.19
  level=level_set)
Error executing job with overrides: []
Traceback (most recent call last):
  File "test.py", line 39, in <module>
    main()
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/hydra/main.py", line 99, in decorated_main
    config_name=config_name,
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/hydra/_internal/utils.py", line 401, in _run_hydra
    overrides=overrides,
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/hydra/_internal/utils.py", line 458, in _run_app
    lambda: hydra.run(
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/hydra/_internal/utils.py", line 223, in run_and_report
    raise ex
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/hydra/_internal/utils.py", line 220, in run_and_report
    return func()
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/hydra/_internal/utils.py", line 461, in <lambda>
    overrides=overrides,
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/hydra/_internal/hydra.py", line 132, in run
    _ = ret.return_value
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/hydra/core/utils.py", line 260, in return_value
    raise self._return_value
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/hydra/core/utils.py", line 186, in run_job
    ret.return_value = task_function(task_cfg)
  File "test.py", line 36, in main
    trainer.test(model, testset, ckpt_path=checkpoint)
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 795, in test
    self, self._test_impl, model, dataloaders, ckpt_path, verbose, datamodule
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/pytorch_lightning/trainer/call.py", line 38, in _call_and_handle_interrupt
    return trainer_fn(*args, **kwargs)
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 842, in _test_impl
    results = self._run(model, ckpt_path=self.ckpt_path)
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 1112, in _run
    results = self._run_stage()
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 1188, in _run_stage
    return self._run_evaluate()
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 1228, in _run_evaluate
    eval_loop_results = self._evaluation_loop.run()
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/pytorch_lightning/loops/loop.py", line 199, in run
    self.advance(*args, **kwargs)
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/pytorch_lightning/loops/dataloader/evaluation_loop.py", line 152, in advance
    dl_outputs = self.epoch_loop.run(self._data_fetcher, dl_max_batches, kwargs)
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/pytorch_lightning/loops/loop.py", line 199, in run
    self.advance(*args, **kwargs)
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/pytorch_lightning/loops/epoch/evaluation_epoch_loop.py", line 137, in advance
    output = self._evaluation_step(**kwargs)
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/pytorch_lightning/loops/epoch/evaluation_epoch_loop.py", line 234, in _evaluation_step
    output = self.trainer._call_strategy_hook(hook_name, *kwargs.values())
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 1494, in _call_strategy_hook
    output = fn(*args, **kwargs)
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/pytorch_lightning/strategies/strategy.py", line 399, in test_step
    return self.model.test_step(*args, **kwargs)
  File "/home/vizua/vid2avatar/code/v2a_model.py", line 269, in test_step
    model_outputs = self.model(batch_inputs)
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/vizua/vid2avatar/code/lib/model/v2a.py", line 159, in forward
    cond, smpl_tfs, feature_vectors=feature_vectors, is_training=self.training)
  File "/home/vizua/vid2avatar/code/lib/model/v2a.py", line 237, in get_rbg_value
    _, gradients, feature_vectors = self.forward_gradient(x, pnts_c, cond, tfs, create_graph=is_training, retain_graph=is_training)
  File "/home/vizua/vid2avatar/code/lib/model/v2a.py", line 264, in forward_gradient
    only_inputs=True)[0]
  File "/home/vizua/anaconda3/envs/v2a/lib/python3.7/site-packages/torch/autograd/__init__.py", line 236, in grad
    inputs, allow_unused, accumulate_grad=False)
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

Is it because my training is not over? If not, do you know what could be wrong please?

Also I expect test.py to produce a 3D animated avatar but could you tell me what's the concrete output format?

@khelkun
Copy link
Author

khelkun commented May 22, 2023

I'm so sorry, I've just realized you already answered to my issue in #7.

N.B: you also answered my second question in #5.

@khelkun khelkun changed the title Requesting more Getting Started details ensors does not require grad and does not have a grad_fn May 22, 2023
@khelkun khelkun changed the title ensors does not require grad and does not have a grad_fn tensors does not require grad and does not have a grad_fn May 22, 2023
@khelkun khelkun closed this as completed May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant