Conversation
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…review Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Enable
torch.compilefor fusibleBasicLinearandBiasoperations, including multi-operation pipelines and Linear + Bias forward fusion. For example,te.ops.Sequential(te.ops.BasicLinear(...), te.ops.Bias(...))can retain the GEMM bias epilogue in the compiled forward pass while dispatching the two backward operations separately through custom ops.This extends the operation compilation interface introduced in #3496. Eager and compiled execution share argument packing, compute methods, and context setup, so their numerical behavior stays aligned.
Type of change
Changes
BasicLinear,Bias, and the supported Linear + Bias forward fusion. Evaluate forward and backward compilation support independently, allowing supported passes to compile when another pass uses an eager-only fusion.BasicLinear, with and without sequence parallelism, including pipelines withBias. Fake kernels account for the shape changes from distributed collectives.in_custom_opdirectly to compute methods. Keep eager storage release andmain_gradbookkeeping insideBasicLinear.backward_compute, without duplicating dispatch or introducing postprocessing hooks. The flag is bound during custom-op registration rather than added to operator schemas.main_gradchecks.Compilation still excludes
accumulate_into_main_grad, CPU activation offload, and unsupported quantizers or extra tensor input/output plumbing. TP support here applies toBasicLinearand its pipelines withBias; standaloneAllReduce/ReduceScatteroperations, including those used by row-parallelte.ops.Linear, still need their own custom ops.Operation API change:
in_custom_opThe
FusibleOperationcompute interface adds a keyword-only execution-context argument to both real compute methods:Direct eager calls keep the default
False. Custom-op registration bindsin_custom_op=Truewithfunctools.partial, so the real kernel receives it whenever execution goes through the registered custom op. It identifies the execution path, including runtime kernel execution, rather than whether Python is currently being traced. The flag is not added to argument dataclasses or the PyTorch operator schema; fake-kernel signatures and compute return values remain unchanged.Operation subclasses using this registration interface must accept the new keyword in their real compute methods, even if they do not need to branch on it. A fusion delegating to another operation's compute method forwards the flag, as Linear + Bias forward fusion does when calling
BasicLinear.forward_compute.This lets shared compute methods retain eager-only side effects while respecting the custom op's non-mutating schema. In
BasicLinear.backward_compute, input storage release (clear_tensor_data) and dummy weight-gradient bookkeeping on the original parameter run only whenin_custom_op=False. Compilation withaccumulate_into_main_gradremains unsupported; the flag preserves its existing eager behavior.Checklist