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

Unable to run HuggingFace's Tutorial Huggy due to TypeError: invalid dtype object error #6144

Closed
kuds opened this issue Sep 12, 2024 · 5 comments
Labels
bug Issue describes a potential bug in ml-agents. stale Issues that have been idle for a while. Automatically closed by a bot if idle for too long.

Comments

@kuds
Copy link

kuds commented Sep 12, 2024

Describe the bug
When trying to follow the HuggingFace's Tutorial Huggy (Google Colab Link), it is erroring out when trying to run the mlagents-learn step. It appears that pytorch is complaining about the default data type that the mlagents are using. I also got the same error when trying to execute 3DBall.

To Reproduce
Steps to reproduce the behavior:

  1. Go to HuggingFace Huggy Tutorial (Google Colab Link)
  2. Execute the cells up to the mlagents-learn command
  3. Run !mlagents-learn ./config/ppo/Huggy.yaml --env=./trained-envs-executables/linux/Huggy/Huggy --run-id="Huggy2" --no-graphics

Console logs / stack traces

Traceback (most recent call last):
  File "/usr/local/bin/mlagents-learn", line 33, in <module>
    sys.exit(load_entry_point('mlagents', 'console_scripts', 'mlagents-learn')())
  File "/usr/local/bin/mlagents-learn", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/content/ml-agents/ml-agents/mlagents/trainers/learn.py", line 2, in <module>
    from mlagents import torch_utils
  File "/content/ml-agents/ml-agents/mlagents/torch_utils/__init__.py", line 1, in <module>
    from mlagents.torch_utils.torch import torch as torch  # noqa
  File "/content/ml-agents/ml-agents/mlagents/torch_utils/torch.py", line 63, in <module>
    set_torch_config(TorchSettings(device=None))
  File "/content/ml-agents/ml-agents/mlagents/torch_utils/torch.py", line 56, in set_torch_config
    torch.set_default_dtype(torch.cuda.FloatTensor)
  File "/usr/local/lib/python3.10/dist-packages/torch/__init__.py", line 1009, in set_default_dtype
    _C._set_default_dtype(d)
TypeError: invalid dtype object: only floating-point types are supported as the default type

Environment (please complete the following information):

  • Unity Version: 2023.2.20f1
  • OS + version: Ubuntu 22.04.3 LTS Jammy (Google Colab)
  • ML-Agents version: 1.1.0.dev0
  • Torch version: 2.4.0+cu121
  • Environment: Huggy
  • Python version: 3.10.12

NOTE: We are unable to help reproduce bugs with custom environments. Please attempt to reproduce your issue with one of the example environments, or provide a minimal patch to one of the environments needed to reproduce the issue.

@kuds kuds added the bug Issue describes a potential bug in ml-agents. label Sep 12, 2024
@kuds kuds changed the title Unable to HuggingFace's Tutorial Huggy due to TypeError: invalid dtype object error Unable to run HuggingFace's Tutorial Huggy due to TypeError: invalid dtype object error Sep 12, 2024
@kuds
Copy link
Author

kuds commented Sep 12, 2024

I found that modifying the default dtype to torch.float32 as recommended by the HuggingFace discord community resolved the issue. Is this the recommended solution or is there something else that I should try?

/content/ml-agents/ml-agents/mlagents/torch_utils/torch.py

if _device.type == "cuda":
    torch.set_default_device(_device.type)
    torch.set_default_dtype(torch.float32)
else:
    torch.set_default_dtype(torch.float32) #torch.set_default_dtype(torch.cuda.FloatTensor)
    logger.debug(f"default Torch device: {_device}")

@Jiancong
Copy link

I found that modifying the default dtype to torch.float32 as recommended by the HuggingFace discord community resolved the issue. Is this the recommended solution or is there something else that I should try?

/content/ml-agents/ml-agents/mlagents/torch_utils/torch.py

if _device.type == "cuda":
    torch.set_default_device(_device.type)
    torch.set_default_dtype(torch.float32)
else:
    torch.set_default_dtype(torch.float32) #torch.set_default_dtype(torch.cuda.FloatTensor)
    logger.debug(f"default Torch device: {_device}")

It works. Thank you.

@liyuan24
Copy link

Also works for me. Thank you!

Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Issues that have been idle for a while. Automatically closed by a bot if idle for too long. label Oct 16, 2024
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale. Please open a new issue for related bugs.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue describes a potential bug in ml-agents. stale Issues that have been idle for a while. Automatically closed by a bot if idle for too long.
Projects
None yet
Development

No branches or pull requests

3 participants