Skip to content

Conversation

tonyf
Copy link

@tonyf tonyf commented Apr 13, 2025

What does this PR do?

When running with torch.compile and ModelParallelStrategy the monkeypatch method of redirecting forward methods through the FabricModule's custom forward method raises an exception if the marked method does not have the same signature as the original forward method.

Instead of monkeypatching forward to the method being called, this PR wraps the function to ensure the right strategy contexts are provided.

This could be cleaned up further by just wrapping the functions in mark_forward_method but that would require touching _LIGHTNING_MODULE_STEP_METHODS = ("training_step", "validation_step", "test_step", "predict_step").

Fixes #20710

Before submitting
  • Was this discussed/agreed via a GitHub issue? (not for typos and docs)
  • [x ] Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

📚 Documentation preview 📚: https://pytorch-lightning--20711.org.readthedocs.build/en/20711/

@github-actions github-actions bot added the fabric lightning.fabric.Fabric label Apr 13, 2025
@Borda
Copy link
Member

Borda commented Apr 14, 2025

seems the falling stand-alone test is a false alarm :)
but the others seems real...

Copy link

codecov bot commented Apr 14, 2025

Codecov Report

❌ Patch coverage is 8.33333% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 81%. Comparing base (2676332) to head (2f5cf7b).
⚠️ Report is 2 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (2676332) and HEAD (2f5cf7b). Click for more details.

HEAD has 104 uploads less than BASE
Flag BASE (2676332) HEAD (2f5cf7b)
cpu 53 27
lightning 31 16
pytest 29 3
python3.11 12 6
python 5 3
lightning_fabric 13 2
python3.10 12 6
python3.12.7 18 9
python3.12 6 3
Additional details and impacted files
@@            Coverage Diff            @@
##           master   #20711     +/-   ##
=========================================
- Coverage      87%      81%     -6%     
=========================================
  Files         268      268             
  Lines       23354    23354             
=========================================
- Hits        20346    18913   -1433     
- Misses       3008     4441   +1433     

@tonyf
Copy link
Author

tonyf commented Apr 14, 2025

Ah! looks like I need to update the redirection tests. Will try to get around to it soon. Currently using this fix in prod successfully

Copy link

stale bot commented Jul 19, 2025

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you need further help see our docs: https://lightning.ai/docs/pytorch/latest/generated/CONTRIBUTING.html#pull-request or ask the assistance of a core contributor here or on Discord. Thank you for your contributions.

@stale stale bot added the won't fix This will not be worked on label Jul 19, 2025
@deependujha
Copy link
Collaborator

Hi @tonyf ,
Could you please take a look and fix failing tests so we can proceed with the merge?

@stale stale bot removed the won't fix This will not be worked on label Aug 4, 2025
@Borda Borda added the waiting on author Waiting on user action, correction, or update label Aug 8, 2025
Borda

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fabric lightning.fabric.Fabric waiting on author Waiting on user action, correction, or update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mark_forward_method does not work with ModelParallelStrategy
3 participants