Lightning-AI / Lightning-AI/pytorch-lightning
Extended support for wrapping container modules (ModuleList, ModuleDict, Sequential) in Fabric
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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