Skip to content

Make learning rate tensor (Backend) - reland#3332

Closed
spcyppt wants to merge 1 commit into
pytorch:mainfrom
spcyppt:export-D65511904
Closed

Make learning rate tensor (Backend) - reland#3332
spcyppt wants to merge 1 commit into
pytorch:mainfrom
spcyppt:export-D65511904

Conversation

@spcyppt

@spcyppt spcyppt commented Nov 6, 2024

Copy link
Copy Markdown
Contributor

Summary:
X-link: https://github.com/facebookresearch/FBGEMM/pull/428

Context problem from Microve:
pt2 adds a guard on the float inputs, and if it is changed, it will be recompiled. Because compilation itself is expensive, each recompilation could take several minutes to >20 mins.
In e2e training, there is a warm up stage where the learning rate is gradually increased to a pre-defined value
e.g., say the final learning rate is 0.02 and the warm step is 10k, learning rate will increase from 0 to 0.02 with a step 0.00002 (each iteration, it increases by 0.00002). So, if we let pt2 recompile, it will recompile 10k times.
For a tensor, the guard is only on its shape; if its shape remains the same, it will not trigger recompilation.


To prevent recompilation, we change learning rate from float to tensor.
This, however, affects existing TBE frontend and backend.

We will enable learning rate being tensor through the new unified interface (D50481991).
For backward compatibility, the old interface (V1), i.e., split_embedding_codegen_lookup_{{ optimizer }}_function and split_embedding_codegen_lookup_{{ optimizer }}_function_cpu will continue to take learning rate as float.

This diff

  • make learning rate tensor in codegen
  • keep learning rate as float for kernel arguments
  • create optional argument to OptimizerArgs for v1 signature
  • make old interface takes tensor as float and converts to tensor before passing to autograd
  • converts learning rate back to float before passing to kernels

Old interface:

          python -> C++ lookup -> autograd -> backend -> kernel
lr type:  (float)     (float)     (tensor)   (tensor)   (float)

PT2 unified interface (D50481991):

          python -> C++ lookup -> autograd -> backend -> kernel
lr type:  (tensor)   (tensor)     (tensor)   (tensor)   (float)

Differential Revision: D65511904

Summary:
X-link: facebookresearch/FBGEMM#428

Context problem from Microve:
pt2 adds a guard on the float inputs, and if it is changed, it will be recompiled. Because compilation itself is expensive, each recompilation could take several minutes to >20 mins. 
In e2e training, there is a warm up stage where the learning rate is gradually increased to a pre-defined value
e.g., say the final learning rate is 0.02 and the warm step is 10k, learning rate will increase from 0 to 0.02 with a step 0.00002 (each iteration, it increases by 0.00002). So, if we let pt2 recompile, it will recompile 10k times.
For a tensor, the guard is only on its shape; if its shape remains the same, it will not trigger recompilation.

----
To prevent recompilation, we change learning rate from float to tensor.
This, however, affects existing TBE frontend and backend.

We will enable learning rate being tensor through the new unified interface (D50481991).
For backward compatibility, the old interface (V1), i.e., `split_embedding_codegen_lookup_{{ optimizer }}_function` and `split_embedding_codegen_lookup_{{ optimizer }}_function_cpu` will continue to take learning rate as `float`.

This diff
- make learning rate tensor in codegen
- keep learning rate as float for kernel arguments
- create optional argument to OptimizerArgs for v1 signature
- make old interface takes tensor as float and converts to tensor before passing to autograd
- converts learning rate back to float before passing to kernels

Old interface:
```
          python -> C++ lookup -> autograd -> backend -> kernel
lr type:  (float)     (float)     (tensor)   (tensor)   (float)
```

PT2 unified interface (D50481991):
```
          python -> C++ lookup -> autograd -> backend -> kernel
lr type:  (tensor)   (tensor)     (tensor)   (tensor)   (float)
```

Differential Revision: D65511904
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D65511904

@netlify

netlify Bot commented Nov 6, 2024

Copy link
Copy Markdown

Deploy Preview for pytorch-fbgemm-docs failed.

Name Link
🔨 Latest commit 51374c5
🔍 Latest deploy log https://app.netlify.com/sites/pytorch-fbgemm-docs/deploys/672ac5c6f0f1670008b9de25

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in 54f9a9b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants