NVIDIA / NVIDIA/apex

Fused Layer Norm not working out-of-the-box with upstream AMP

Open
#979 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9k
Forks
1.5k
Avg merge
2d 4h
Merged PRs (30d)
3

Description

Error when using fusedlayernorm with upstream amp. pasting here the log I get from Bobby Chen:

  File "/workspace/electra/modeling_utils.py", line 1307, in forward
    hidden_states = self.LayerNorm(hidden_states + input_tensor)
  File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 577, in __call__
    result = self.forward(*input, **kwargs)
  File "/opt/conda/lib/python3.6/site-packages/apex/normalization/fused_layer_norm.py", line 159, in forward
    input, self.weight, self.bias, self.normalized_shape,self.eps)
  File "/opt/conda/lib/python3.6/site-packages/apex/normalization/fused_layer_norm.py", line 25, in forward
    input_, ctx.normalized_shape, weight_, bias_, ctx.eps)
RuntimeError: expected scalar type Half but found Float

I think this is due to issue described here, and fused layer norm need to be updated
https://pytorch.org/docs/stable/notes/amp_examples.html#amp-custom-examples

@mcarilli @ptrblck to confirm

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with apex/normalization/fused_layer_norm.py, especially the forward path shown in the traceback, and review the upstream AMP custom examples linked in the issue. Reproduce the fused layer norm call from modeling_utils.py with upstream AMP; done means the operation no longer fails with the Half-versus-Float scalar type error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.