[PyTorch] Add option to pass kwargs to CUDA graph module #945
+331
−50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses a request to modify
te.make_graphed_callables
so we can pass in kwargs like the attention masks. See vasunvidia@d0a1057 for an initial implementation. If kwargs are provided inte.make_graphed_callables
(via thesample_kwargs
), they must also be provided whenever the graph is replayed. Note that only tensors are accepted as positional args or kwargs, since otherwise we run into another pile of design problems (what happens if the args differ during graph capture and graph replays?).To be honest, I don't really like this approach. Ideally
te.make_graphed_callables
should match the API oftorch.cuda.make_graphed_callables
, which only supports positional args. But the best ways to handle modules with kwargs in plain PyTorch are creating wrappers that handle the kwargs:This is quite clunky. If we accept API divergence from PyTorch, it becomes much cleaner:
While I was touching the code, I also commented and added tests for the custom integration with Megatron-LM interleaved pipeline parallelism.
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: