Lightning-AI / Lightning-AI/pytorch-lightning

Extended support for wrapping container modules (ModuleList, ModuleDict, Sequential) in Fabric

Open
#18,427 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

fabric feature
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

Description & Motivation

Fabric's setup methods wrap the user's nn.Module in a FabricModule. This one forwards all calls to the original module with a few exceptions where we add additional logic before and after.

There are three additional special module types in PyTorch: Sequential, ModuleList, and ModuleDict. These have additional methods like __getitem__ for advanced indexing. The FabricModule does not support handling these:

module = torch.nn.Sequential(torch.nn.Linear(1, 1), torch.nn.ReLU())
fabric_module = fabric.setup(module)
module[0]  # works
fabric_module[0]  # fails

module = torch.nn.ModuleDict({"module_key": torch.nn.Linear(1, 1)})
fabric_module = fabric.setup(module)
module["module_key"]  # works
fabric_module["module_key"]  # fails
Pitch

Implement the dunder methods (or a subset of them) for the FabricModule wrapper.

Alternatives

Keep as is, but document that the desired functionality can be accessed via fabric_module.module.

Additional context

No response

cc @borda

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 locating Fabric's setup methods and the FabricModule wrapper, then compare its behavior with PyTorch's Sequential, ModuleList, and ModuleDict container methods linked in the issue. Decide which dunder methods are needed for indexing and verify that wrapped containers support the examples shown in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
ai
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.