-
Notifications
You must be signed in to change notification settings - Fork 615
add inductor lite mode #2005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
BoyuanFeng
wants to merge
21
commits into
main
Choose a base branch
from
bf/inductor-lite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
add inductor lite mode #2005
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7e8185f
add lite mode
BoyuanFeng cd6a187
add lite mode for dsv3
BoyuanFeng 96f24bb
Merge branch 'main' into bf/inductor-lite
BoyuanFeng f6307da
fix conflict
BoyuanFeng 507e823
refactor
BoyuanFeng 43cc640
Merge branch 'main' into bf/inductor-lite
BoyuanFeng 234eda8
lint
BoyuanFeng 215804e
refactor
BoyuanFeng f790c61
nit
BoyuanFeng e887be7
add test
BoyuanFeng 0b43140
nit
BoyuanFeng 26b4e1d
nit
BoyuanFeng bcf079e
more tests and fixes
BoyuanFeng cdccffa
nit
BoyuanFeng 7052b24
patch fake_tensor_cache_enabled for a known issue
BoyuanFeng 87f21a9
Merge branch 'main' into bf/inductor-lite
BoyuanFeng d5aa705
lint
BoyuanFeng f8ae2d9
Merge branch 'main' into bf/inductor-lite
BoyuanFeng 249106e
nit
BoyuanFeng 6f0c765
Merge branch 'main' into bf/inductor-lite
BoyuanFeng ad310c8
Merge branch 'main' into bf/inductor-lite
BoyuanFeng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| """ | ||
| Inductor lite pass for the compiler toolkit. | ||
|
|
||
| This module provides inductor lite pass that can be applied to graph modules | ||
| during compilation. | ||
| """ | ||
| from typing import Optional | ||
|
|
||
| import torch | ||
| from torchtitan.tools.logging import logger | ||
|
|
||
|
|
||
| def get_inductor_lite_fw_compiler(extra_config: Optional[dict] = None): | ||
| from torch._inductor import lite_mode_options | ||
| from torch._inductor.compile_fx import compile_fx_inner | ||
|
|
||
| context = torch._guards.TracingContext.try_get() | ||
|
|
||
| if not context or not context.fw_metadata: | ||
| logger.warn("No context or fw_metadata available") | ||
| static_input_idxs = () | ||
| else: | ||
| static_input_idxs = context.fw_metadata.static_input_indices | ||
|
|
||
| inductor_config = lite_mode_options | ||
| if extra_config: | ||
| inductor_config.update(extra_config) | ||
|
|
||
| def fw_compiler(gm: torch.fx.GraphModule, example_inputs: tuple): | ||
| with torch._inductor.config.patch(inductor_config): | ||
| compiled_fn = compile_fx_inner( | ||
| gm, | ||
| example_inputs, | ||
| static_input_idxs=static_input_idxs, | ||
| is_backward=False, | ||
| ) | ||
| return compiled_fn | ||
|
|
||
| return fw_compiler | ||
|
|
||
|
|
||
| def get_inductor_lite_bw_compiler(extra_config: Optional[dict] = None): | ||
| from torch._inductor import lite_mode_options | ||
| from torch._inductor.compile_fx import compile_fx_inner | ||
| from torch._inductor.utils import count_tangents | ||
|
|
||
| inductor_config = lite_mode_options | ||
| if extra_config: | ||
| inductor_config.update(extra_config) | ||
|
|
||
| def bw_compiler(gm: torch.fx.GraphModule, example_inputs: tuple): | ||
| fixed = count_tangents(gm) | ||
|
|
||
| with torch._inductor.config.patch(inductor_config): | ||
| compiled_fn = compile_fx_inner( | ||
| gm, | ||
| example_inputs, | ||
| static_input_idxs=list(range(fixed)), | ||
| is_backward=True, | ||
| ) | ||
| return compiled_fn | ||
|
|
||
| return bw_compiler |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.