question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Windows run MNIST example gets `AttributeError: module 'torch' has no attribute 'torch_version'`

See original GitHub issue

Describe the bug On windows 10 platform, try to run MNIST example, got an error AttributeError: module 'torch' has no attribute 'torch_version'. The error is located at file utils/tokenizers.py, line 892, as follows,

# utils/tokenizers.py
892 if torch.torch_version.TorchVersion(torchtext.__version__) >= (0, 12, 0):

To Reproduce On windows, use pipenv install ludwig to install the ludwig(v0.5). Then, use ludwig datasets download mnist to download the MNIST dataset and process. There are actually some issues related to Windows paths, but I’ve avoided them. After that, create the config.yaml to configure the model and training exactly same as shown in the official docs. Finally, when use 'ludwig train --datasets mnist_datasets.csv --config config.yaml`, I got the error above.

config.yaml is exactly the same as in the official docs.

input_features:
- name: image_path
  type: image
  encoder: stacked_cnn
  conv_layers:
    - num_filters: 32
      filter_size: 3
      pool_size: 2
      pool_stride: 2
    - num_filters: 64
      filter_size: 3
      pool_size: 2
      pool_stride: 2
      dropout: 0.4
  fc_layers:
    - output_size: 128
      dropout: 0.4

output_features:
  - name: label
    type: category

trainer:
  epochs: 5

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: Windows
  • Version: 10
  • Python version: 3.9
  • Ludwig version: 0.5

Additional context

Full Error Stack:

Traceback (most recent call last):
  File "D:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "D:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\Scripts\ludwig.exe\__main__.py", line 7, in <module>
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\cli.py", line 158, in main
    CLI()
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\cli.py", line 63, in __init__
    getattr(self, args.command)()
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\cli.py", line 66, in train
    from ludwig import train
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\train.py", line 23, in <module>
    from ludwig.api import LudwigModel
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\api.py", line 38, in <module>
    from ludwig.backend import Backend, initialize_backend
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\backend\__init__.py", line 20, in <module>
    from ludwig.backend.base import Backend, LocalBackend
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\backend\base.py", line 25, in <module>
    from ludwig.models.ecd import ECD
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\models\ecd.py", line 10, in <module>
    from ludwig.combiners.combiners import Combiner, get_combiner_class
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\combiners\combiners.py", line 25, in <module>
    import ludwig.marshmallow.marshmallow_schema_utils as schema
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\marshmallow\marshmallow_schema_utils.py", line 8, in <module>
    from ludwig.modules.reduction_modules import reduce_mode_registry
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\modules\reduction_modules.py", line 19, in <module>
    from ludwig.modules.attention_modules import FeedForwardAttentionReducer
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\modules\attention_modules.py", line 21, in <module>
    from ludwig.utils.torch_utils import get_activation, LudwigModule
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\utils\torch_utils.py", line 12, in <module>
    from ludwig.utils.strings_utils import SpecialSymbol
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\utils\strings_utils.py", line 30, in <module>
    from ludwig.utils.tokenizers import tokenizer_registry
  File "C:\Users\houlu\.virtualenvs\Ludwig-APhWrIpG\lib\site-packages\ludwig\utils\tokenizers.py", line 893, in <module>
    if torch.torch_version.TorchVersion(torchtext.__version__) >= (0, 12, 0):
AttributeError: module 'torch' has no attribute 'torch_version'

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
geoffreyanguscommented, May 18, 2022

Thanks @houluy for the quick response!

Depending on when you installed Ludwig, it is possible that its package requirements were outdated. They should be fixed by #1998.

In any case, I recommend running pip install -U torch torchtext torchvision torchaudio within your virtual environment to get the most recent version of those dependencies.

0reactions
houluycommented, May 19, 2022

@geoffreyangus Thanks for your help!

I reinstall the latest version of torch(GPU) packages, and it works. Thanks again for your time!

Here’s my Pipfile file in case others run into the same issue and can refer to it

[[source]]
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
verify_ssl = true
name = "pypi"

[[source]]
url = "https://download.pytorch.org/whl/cu113"
verify_ssl = true
name = "torch"

[packages]
ludwig = {extras = ["image"], version = "*", index="pypi"}
torch = {version="*", index="torch"}
torchvision = {version="*", index="torch"}
torchaudio = {version="*", index="torch"}
torchtext = {version="*", index="torch"}

[dev-packages]

[requires]
python_version = "3.9"
Read more comments on GitHub >

github_iconTop Results From Across the Web

PyTorch, AttributeError: module 'shape' has no attribute ''
I got it from a tutorial online, and it basically just downloaded the datasets and try to get the shape of it. train_loader...
Read more >
Super-Resolution gives me "AttributeError: module 'torch' has ...
Whenever I try to use the the super-resolution example I'm getting this error. But when I run other scripts that use pytorch everything...
Read more >
attributeerror: module 'torchvision' has no attribute '__version__'
When we are running a pytorch script, we get AttributeError: module 'torchvision' has no attribute '__version__'. In this tutorial, we will introduce how...
Read more >
AttributeError: module 'transforms' has no attribute 'Normalize'
It seems you are importing a custom transforms module and not torchvision.transforms , which doesn't seem to have the Normalize transformation.
Read more >
PyTorch Lightning
The future of Lightning is here - get started for free now! ... from torchvision.datasets import MNIST ... Change one trainer param and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found