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

make torch.amp.autocast more generic #125103

Closed
wants to merge 12 commits into from

Commits on Apr 27, 2024

  1. make torch.amp.autocast more generic

    [ghstack-poisoned]
    guangyey committed Apr 27, 2024
    Configuration menu
    Copy the full SHA
    054a451 View commit details
    Browse the repository at this point in the history

Commits on Apr 28, 2024

  1. Update on "[WIP] make torch.amp.autocast more generic"

    cc mcarilli ptrblck leslie-fang-intel jgong5 ezyang msaroufim bdhirsh anijain2305 chauhang voznesenskym penguinwu EikanWang Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng
    
    [ghstack-poisoned]
    guangyey committed Apr 28, 2024
    Configuration menu
    Copy the full SHA
    2b6089e View commit details
    Browse the repository at this point in the history

Commits on Apr 29, 2024

  1. Update on "[WIP] make torch.amp.autocast more generic"

    cc mcarilli ptrblck leslie-fang-intel jgong5 ezyang msaroufim bdhirsh anijain2305 chauhang voznesenskym penguinwu EikanWang Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng
    
    [ghstack-poisoned]
    guangyey committed Apr 29, 2024
    Configuration menu
    Copy the full SHA
    c6e6fac View commit details
    Browse the repository at this point in the history
  2. Update on "[WIP] make torch.amp.autocast more generic"

    cc mcarilli ptrblck leslie-fang-intel jgong5 ezyang msaroufim bdhirsh anijain2305 chauhang voznesenskym penguinwu EikanWang Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng
    
    [ghstack-poisoned]
    guangyey committed Apr 29, 2024
    Configuration menu
    Copy the full SHA
    58cabab View commit details
    Browse the repository at this point in the history

Commits on May 6, 2024

  1. Update on "[WIP] make torch.amp.autocast more generic"

    cc mcarilli ptrblck leslie-fang-intel jgong5 ezyang msaroufim bdhirsh anijain2305 chauhang voznesenskym penguinwu EikanWang Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng
    
    [ghstack-poisoned]
    guangyey committed May 6, 2024
    Configuration menu
    Copy the full SHA
    a49c133 View commit details
    Browse the repository at this point in the history
  2. Update on "[WIP] make torch.amp.autocast more generic"

    cc mcarilli ptrblck leslie-fang-intel jgong5 ezyang msaroufim bdhirsh anijain2305 chauhang voznesenskym penguinwu EikanWang Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng
    
    [ghstack-poisoned]
    guangyey committed May 6, 2024
    Configuration menu
    Copy the full SHA
    7e129ca View commit details
    Browse the repository at this point in the history

Commits on May 7, 2024

  1. Update on "make torch.amp.autocast more generic"

    # Motivation
    As discussed in [#124479](#124479), `torch.amp.autocast` can NOT be completely equivalent to `torch.cuda.amp.autocast` and `torch.cpu.amp.autocast` since `torch.amp.autocast` has NOT the default `dtype` for CPU (`torch.bfloat16` by default) and CUDA (`torch.float16` by default) respectively. We would like `torch.amp.autocast` to be more generic to help the developer/customer write the device-agnostic code. Because there are not enough reasons to add device-specific autocast `torch.xxx.amp.autocast` for each device backend.
    
    # Solution
    When `None` is passed to `dtype`, we should use `torch.get_autocast_dtype` to get the related dtype for each backend. Meanwhile, `torch.get_autocast_dtype` is necessary to be supported in JIT path for BC.
    
    # Additional Context
    With this PR, `torch.amp.autocast(device_type='cuda')` is equivalent to `torch.cuda.amp.autocast`.
    
    cc mcarilli ptrblck leslie-fang-intel jgong5 ezyang msaroufim bdhirsh anijain2305 chauhang voznesenskym penguinwu EikanWang Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng
    
    [ghstack-poisoned]
    guangyey committed May 7, 2024
    Configuration menu
    Copy the full SHA
    b00a0bd View commit details
    Browse the repository at this point in the history
  2. Update on "make torch.amp.autocast more generic"

    # Motivation
    As discussed in [#124479](#124479), `torch.amp.autocast` can NOT be completely equivalent to `torch.cuda.amp.autocast` and `torch.cpu.amp.autocast` since `torch.amp.autocast` has NOT the default `dtype` for CPU (`torch.bfloat16` by default) and CUDA (`torch.float16` by default) respectively. We would like `torch.amp.autocast` to be more generic to help the developer/customer write the device-agnostic code. Because there are not enough reasons to add device-specific autocast `torch.xxx.amp.autocast` for each device backend.
    
    # Solution
    When `None` is passed to `dtype`, we should use `torch.get_autocast_dtype` to get the related dtype for each backend. Meanwhile, `torch.get_autocast_dtype` is necessary to be supported in JIT path for BC.
    
    # Additional Context
    With this PR, `torch.amp.autocast(device_type='cuda')` is equivalent to `torch.cuda.amp.autocast`.
    
    cc mcarilli ptrblck leslie-fang-intel jgong5 ezyang msaroufim bdhirsh anijain2305 chauhang voznesenskym penguinwu EikanWang Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng
    
    [ghstack-poisoned]
    guangyey committed May 7, 2024
    Configuration menu
    Copy the full SHA
    73d9468 View commit details
    Browse the repository at this point in the history
  3. Update on "make torch.amp.autocast more generic"

    # Motivation
    As discussed in [#124479](#124479), `torch.amp.autocast` can NOT be completely equivalent to `torch.cuda.amp.autocast` and `torch.cpu.amp.autocast` since `torch.amp.autocast` has NOT the default `dtype` for CPU (`torch.bfloat16` by default) and CUDA (`torch.float16` by default) respectively. We would like `torch.amp.autocast` to be more generic to help the developer/customer write the device-agnostic code. Because there are not enough reasons to add device-specific autocast `torch.xxx.amp.autocast` for each device backend.
    
    # Solution
    When `None` is passed to `dtype`, we should use `torch.get_autocast_dtype` to get the related dtype for each backend. Meanwhile, `torch.get_autocast_dtype` is necessary to be supported in JIT path for BC.
    
    # Additional Context
    With this PR, `torch.amp.autocast(device_type='cuda')` is equivalent to `torch.cuda.amp.autocast`.
    Add two new UTs to cover this change in eager and jit path respectively.
    
    cc mcarilli ptrblck leslie-fang-intel jgong5 ezyang msaroufim bdhirsh anijain2305 chauhang voznesenskym penguinwu EikanWang Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng
    
    [ghstack-poisoned]
    guangyey committed May 7, 2024
    Configuration menu
    Copy the full SHA
    d20ca90 View commit details
    Browse the repository at this point in the history

Commits on May 8, 2024

  1. Update on "make torch.amp.autocast more generic"

    # Motivation
    As discussed in [#124479](#124479), `torch.amp.autocast` can NOT be completely equivalent to `torch.cuda.amp.autocast` and `torch.cpu.amp.autocast` since `torch.amp.autocast` has NOT the default `dtype` for CPU (`torch.bfloat16` by default) and CUDA (`torch.float16` by default) respectively. We would like `torch.amp.autocast` to be more generic to help the developer/customer write the device-agnostic code. Because there are not enough reasons to add device-specific autocast `torch.xxx.amp.autocast` for each device backend.
    
    # Solution
    When `None` is passed to `dtype`, we should use `torch.get_autocast_dtype` to get the related dtype for each backend. Meanwhile, `torch.get_autocast_dtype` is necessary to be supported in JIT path for BC.
    
    # Additional Context
    With this PR, `torch.amp.autocast(device_type='cuda')` is equivalent to `torch.cuda.amp.autocast`.
    Add two new UTs to cover this change in eager and jit path respectively.
    
    cc mcarilli ptrblck leslie-fang-intel jgong5 ezyang msaroufim bdhirsh anijain2305 chauhang voznesenskym penguinwu EikanWang Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng
    
    [ghstack-poisoned]
    guangyey committed May 8, 2024
    Configuration menu
    Copy the full SHA
    4e211cd View commit details
    Browse the repository at this point in the history
  2. Update on "make torch.amp.autocast more generic"

    # Motivation
    As discussed in [#124479](#124479), `torch.amp.autocast` can NOT be completely equivalent to `torch.cuda.amp.autocast` and `torch.cpu.amp.autocast` since `torch.amp.autocast` has NOT the default `dtype` for CPU (`torch.bfloat16` by default) and CUDA (`torch.float16` by default) respectively. We would like `torch.amp.autocast` to be more generic to help the developer/customer write the device-agnostic code. Because there are not enough reasons to add device-specific autocast `torch.xxx.amp.autocast` for each device backend.
    
    # Solution
    When `None` is passed to `dtype`, we should use `torch.get_autocast_dtype` to get the related dtype for each backend. Meanwhile, `torch.get_autocast_dtype` is necessary to be supported in JIT path for BC.
    
    # Additional Context
    With this PR, `torch.amp.autocast(device_type='cuda')` is equivalent to `torch.cuda.amp.autocast`.
    Add two new UTs to cover this change in eager and jit path respectively.
    
    cc mcarilli ptrblck leslie-fang-intel jgong5 ezyang msaroufim bdhirsh anijain2305 chauhang voznesenskym penguinwu EikanWang Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng
    
    [ghstack-poisoned]
    guangyey committed May 8, 2024
    Configuration menu
    Copy the full SHA
    63d4d7e View commit details
    Browse the repository at this point in the history
  3. Update on "make torch.amp.autocast more generic"

    # Motivation
    As discussed in [#124479](#124479), `torch.amp.autocast` can NOT be completely equivalent to `torch.cuda.amp.autocast` and `torch.cpu.amp.autocast` since `torch.amp.autocast` has NOT the default `dtype` for CPU (`torch.bfloat16` by default) and CUDA (`torch.float16` by default) respectively. We would like `torch.amp.autocast` to be more generic to help the developer/customer write the device-agnostic code. Because there are not enough reasons to add device-specific autocast `torch.xxx.amp.autocast` for each device backend.
    
    # Solution
    When `None` is passed to `dtype`, we should use `torch.get_autocast_dtype` to get the related dtype for each backend. Meanwhile, `torch.get_autocast_dtype` is necessary to be supported in JIT path for BC.
    
    # Additional Context
    With this PR, `torch.amp.autocast(device_type='cuda')` is equivalent to `torch.cuda.amp.autocast`.
    Add two new UTs to cover this change in eager and jit path respectively.
    
    cc mcarilli ptrblck leslie-fang-intel jgong5 ezyang msaroufim bdhirsh anijain2305 chauhang voznesenskym penguinwu EikanWang Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng
    
    [ghstack-poisoned]
    guangyey committed May 8, 2024
    Configuration menu
    Copy the full SHA
    e11d24b View commit details
    Browse the repository at this point in the history