Skip to content

torch.jit.script raises unrelated deprecation error #15917

@jharris1679

Description

@jharris1679

Bug description

When compiling a lightning model to torchscript, a seemingly unrelated error is produced:

Traceback (most recent call last):
  File "/home/train.py", line 148, in <module>
    train(args)
  File "/home/train.py", line 46, in train
    compiled_model = torch.jit.script(initialized_model)
  File "/usr/local/lib/python3.10/dist-packages/torch/jit/_script.py", line 1286, in script
    return torch.jit._recursive.create_script_module(
  File "/usr/local/lib/python3.10/dist-packages/torch/jit/_recursive.py", line 473, in create_script_module
    concrete_type = get_module_concrete_type(nn_module, share_types)
  File "/usr/local/lib/python3.10/dist-packages/torch/jit/_recursive.py", line 424, in get_module_concrete_type
    concrete_type = concrete_type_store.get_or_create_concrete_type(nn_module)
  File "/usr/local/lib/python3.10/dist-packages/torch/jit/_recursive.py", line 365, in get_or_create_concrete_type
    concrete_type_builder = infer_concrete_type_builder(nn_module)
  File "/usr/local/lib/python3.10/dist-packages/torch/jit/_recursive.py", line 273, in infer_concrete_type_builder
    overloads.update(get_overload_name_mapping(get_overload_annotations(nn_module, ignored_properties)))
  File "/usr/local/lib/python3.10/dist-packages/torch/jit/_recursive.py", line 639, in get_overload_annotations
    item = getattr(mod, name, None)
  File "/usr/local/lib/python3.10/dist-packages/pytorch_lightning/_graveyard/core.py", line 39, in _use_amp
    raise RuntimeError(
RuntimeError: `LightningModule.use_amp` was deprecated in v1.6 and is no longer accessible as of v1.8. Please use `Trainer.amp_backend`.

How to reproduce the bug

trainer.fit(model, data_module)
compiled_model = torch.jit.script(model)

Error messages and logs

2022-12-06 04:21:14.032 | INFO     | __main__:train:44 - Training complete, saving model artifact
Traceback (most recent call last):
  File "/home/train.py", line 148, in <module>
    train(args)
  File "/home/train.py", line 46, in train
    compiled_model = torch.jit.script(initialized_model)
  File "/usr/local/lib/python3.10/dist-packages/torch/jit/_script.py", line 1286, in script
    return torch.jit._recursive.create_script_module(
  File "/usr/local/lib/python3.10/dist-packages/torch/jit/_recursive.py", line 473, in create_script_module
    concrete_type = get_module_concrete_type(nn_module, share_types)
  File "/usr/local/lib/python3.10/dist-packages/torch/jit/_recursive.py", line 424, in get_module_concrete_type
    concrete_type = concrete_type_store.get_or_create_concrete_type(nn_module)
  File "/usr/local/lib/python3.10/dist-packages/torch/jit/_recursive.py", line 365, in get_or_create_concrete_type
    concrete_type_builder = infer_concrete_type_builder(nn_module)
  File "/usr/local/lib/python3.10/dist-packages/torch/jit/_recursive.py", line 273, in infer_concrete_type_builder
    overloads.update(get_overload_name_mapping(get_overload_annotations(nn_module, ignored_properties)))
  File "/usr/local/lib/python3.10/dist-packages/torch/jit/_recursive.py", line 639, in get_overload_annotations
    item = getattr(mod, name, None)
  File "/usr/local/lib/python3.10/dist-packages/pytorch_lightning/_graveyard/core.py", line 39, in _use_amp
    raise RuntimeError(
RuntimeError: `LightningModule.use_amp` was deprecated in v1.6 and is no longer accessible as of v1.8. Please use `Trainer.amp_backend`.

Environment

Current environment
root@fffd3962435c:/home# python3 collect_env_details.py
/usr/lib/python3/dist-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: 1.1build1 is an invalid version and will not be supported in a future release
  warnings.warn(
* CUDA:
	- GPU:               None
	- available:         False
	- version:           None
* Lightning:
	- lightning-utilities: 0.3.0
	- pytorch-lightning: 1.8.3
	- torch:             1.13.0+cpu
	- torchmetrics:      0.10.2
* Packages:
	- aiohttp:           3.8.3
	- aiosignal:         1.3.1
	- async-timeout:     4.0.2
	- attrs:             22.1.0
	- blinker:           1.4
	- boto3:             1.21.21
	- botocore:          1.24.46
	- certifi:           2022.9.24
	- charset-normalizer: 2.1.1
	- contourpy:         1.0.6
	- cryptography:      3.4.8
	- cycler:            0.11.0
	- dbus-python:       1.2.18
	- distro:            1.7.0
	- distro-info:       1.1build1
	- fire:              0.4.0
	- fonttools:         4.38.0
	- frozenlist:        1.3.3
	- fsspec:            2022.11.0
	- httplib2:          0.20.2
	- idna:              3.4
	- importlib-metadata: 4.6.4
	- jeepney:           0.7.1
	- jmespath:          1.0.1
	- joblib:            1.2.0
	- keyring:           23.5.0
	- kiwisolver:        1.4.4
	- launchpadlib:      1.10.16
	- lazr.restfulclient: 0.14.4
	- lazr.uri:          1.0.6
	- lightning-utilities: 0.3.0
	- llfuse:            1.3.8
	- loguru:            0.6.0
	- matplotlib:        3.6.2
	- more-itertools:    8.10.0
	- multidict:         6.0.3
	- numpy:             1.23.5
	- oauthlib:          3.2.0
	- packaging:         21.3
	- pandas:            1.5.2
	- pillow:            9.3.0
	- pip:               22.3.1
	- protobuf:          3.20.1
	- pyarrow:           10.0.1
	- pygobject:         3.42.1
	- pyjwt:             2.3.0
	- pyparsing:         2.4.7
	- python-apt:        2.3.0+ubuntu2.1
	- python-dateutil:   2.8.2
	- pytorch-lightning: 1.8.3
	- pytz:              2022.6
	- pyyaml:            6.0
	- requests:          2.28.1
	- s3transfer:        0.5.2
	- scikit-learn:      1.0.2
	- scipy:             1.9.3
	- secretstorage:     3.3.1
	- setuptools:        59.6.0
	- six:               1.16.0
	- tensorboardx:      2.5.1
	- termcolor:         2.1.1
	- threadpoolctl:     3.1.0
	- torch:             1.13.0+cpu
	- torchmetrics:      0.10.2
	- tqdm:              4.64.1
	- typing-extensions: 4.4.0
	- unattended-upgrades: 0.1
	- urllib3:           1.26.13
	- wadllib:           1.3.6
	- wheel:             0.37.1
	- yarl:              1.8.2
	- zipp:              1.0.0
* System:
	- OS:                Linux
	- architecture:
		- 64bit
		- ELF
	- processor:         x86_64
	- python:            3.10.6
	- version:           #1 SMP PREEMPT Thu Mar 17 17:05:54 UTC 2022

More info

No response

cc @carmocca @justusschock @awaelchli @Borda

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinglightningmodulepl.LightningModule

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions