NVIDIA / NVIDIA/TransformerEngine

TransformerLayer implementation is overly complex and difficult to follow

Open
#2,903 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
3.5k
Forks
831
Avg merge
3d 11h
Merged PRs (30d)
65

Description

https://github.com/NVIDIA/TransformerEngine/blob/5aa4823dcc4942cadc2862adebef917758b6dc05/transformer_engine/pytorch/transformer.py#L70

I understand that you want to implement a single TransformerLayer class to support various model architectures.

However, this design leads to an issue: the code inside the TransformerLayer class has become overly complex, with too many parameters and a large number of if-else statements. For beginners, it is really difficult to figure out how to configure the parameters to fit their own model structures.

I'm curious why you didn't design it like the Hugging Face Transformers framework, where one model corresponds to one file:
https://github.com/huggingface/transformers/tree/main/src/transformers/models

This kind of design is much more user-friendly, because users only need to focus on the code they care about.

Contributor guide

Open the contributing guide

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 by reading transformer_engine/pytorch/transformer.py around line 70, then compare its single TransformerLayer design with the linked Hugging Face model layout. The issue does not define a specific decomposition, acceptance criteria, or tests, so the desired refactor and definition of done would need agreement before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.