8000 Make `Adam`, `AdamW` work with nonzero-dim Tensor betas by zeshengzong · Pull Request #149939 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

Make Adam, AdamW work with nonzero-dim Tensor betas #149939

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

zeshengzong
Copy link
Contributor
@zeshengzong zeshengzong commented Mar 25, 2025

Fixes #147921

Changes

  • Convert tensor betas using _to_scalar
  • Change annotation of betas param
  • Change param type in docs

Test Result

pytest -s test/test_optim.py -k test_tensor_lr -vv

image

image

Copy link
pytorch-bot bot commented Mar 25, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/149939

Note: Links to docs will display an error until the docs builds have been completed.

❌ 5 New Failures, 1 Unrelated Failure

As of commit 2536db1 with merge base 27e9d9b (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@zeshengzong zeshengzong marked this pull request as ready for review March 25, 2025 07:36
@soulitzer soulitzer added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Mar 26, 2025
@albanD albanD removed their request for review April 9, 2025 16:58
zeshengzong and others added 4 commits May 13, 2025 11:01
Co-authored-by: Jane (Yuan) Xu <31798555+janeyx99@users.noreply.github.com>
Co-authored-by: Jane (Yuan) Xu <31798555+janeyx99@users.noreply.github.com>
"betas": (torch.tensor([[[0.9]]]), torch.tensor([[0.99]])),
"amsgrad": False,
"capturable": True,
"fused": True,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @janeyx99 , looks like fused=True failed with complex type due to backend not supported yet, is there a way to control input type in test and skip complex type? Thanks

Failed in here

if not (p.device.type in fused_supported_devices and torch.is_floating_point(p)):
raise RuntimeError(
"`fused=True` requires all the params to be floating point Tensors of "
f"supported devices: {fused_supported_devices} but {p.dtype} and {p.device.type}"

pytest -s test/test_optim.py -k test_complex_2d_AdamW_cuda_complex64

______________________________________________________________________________________________ TestOptimRenewedCUDA.test_complex_2d_AdamW_cuda_complex64 _______________________________________________________________________________________________
Traceback (most recent call last):
  File "/home/zong/miniconda3/envs/torch/lib/python3.12/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/home/zong/miniconda3/envs/torch/lib/python3.12/unittest/case.py", line 634, in run
    self._callTestMethod(testMethod)
  File "/home/zong/miniconda3/envs/torch/lib/python3.12/unittest/case.py", line 589, in _callTestMethod
    if method() is not None:
       ^^^^^^^^
  File "/home/zong/code/pytorch/torch/testing/_internal/common_utils.py", line 3154, in wrapper
    method(*args, **kwargs)
  File "/home/zong/code/pytorch/torch/testing/_internal/common_utils.py", line 3154, in wrapper
    method(*args, **kwargs)
  File "/home/zong/code/pytorch/torch/testing/_internal/common_device_type.py", line 446, in instantiated_test
    raise rte
  File "/home/zong/code/pytorch/torch/testing/_internal/common_device_type.py", line 426, in instantiated_test
    result = test(self, **param_kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/zong/code/pytorch/torch/testing/_internal/common_utils.py", line 1612, in wrapper
    fn(*args, **kwargs)
  File "/home/zong/code/pytorch/torch/testing/_internal/common_optimizers.py", line 226, in test_wrapper
    return test(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/zong/code/pytorch/torch/testing/_internal/common_device_type.py", line 1215, in dep_fn
    return fn(slf, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/zong/code/pytorch/test/test_optim.py", line 664, in test_complex_2d
    optim1.step()
  File "/home/zong/code/pytorch/torch/optim/optimizer.py", line 507, in wrapper
    out = func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/zong/code/pytorch/torch/optim/optimizer.py", line 80, in _use_grad
    ret = func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/zong/code/pytorch/torch/optim/adam.py", line 237, in step
    has_complex = self._init_group(
                  ^^^^^^^^^^^^^^^^^
  File "/home/zong/code/pytorch/torch/optim/adam.py", line 163, in _init_group
    _device_dtype_check_for_fused(p)
  File "/home/zong/code/pytorch/torch/optim/optimizer.py", line 197, in _device_dtype_check_for_fused
    raise RuntimeError(
RuntimeError: `fused=True` requires all the params to be floating point Tensors of supported devices: ['mps', 'cuda', 'xpu', 'hpu', 'cpu', 'privateuseone'] but torch.complex64 and cuda

To execute this test, run the following from the base repo dir:
    python test/test_optim.py TestOptimRenewedCUDA.test_complex_2d_AdamW_cuda_complex64

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
=============================================================================================================== short test summary info ================================================================================================================
FAILED [2.1007s] test/test_optim.py::TestOptimRenewedCUDA::test_complex_2d_AdamW_cuda_complex64 - RuntimeError: `fused=True` requires all the params to be floating point Tensors of supported devices: ['mps', 'cuda', 'xpu', 'hpu', 'cpu', 'privateuseone'] but torch.complex64 and cuda

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, we shouldn't specify "fused" in these OptimInfos after all--that was my bad. (Please delete this config)

What I care about is that the fused optimizer is tested with these betas. Can you confirm such a configuration with Tensor betas and fused is tested in one of the existing fused tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open source release notes: optim triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adam doesn't work with nonzero-dim Tensor betas
4 participants
0