Repository navigation
config compile backend - #1768
Conversation
stack-info: PR: #1768, branch: IvanKobzarev/stack/1
7228b8f to
95810a2
Compare
|
|
||
| def forward(self, x): | ||
| return self.w2(F.silu(self.w1(x)) * self.w3(x)) | ||
| return self.w2(F.relu(self.w1(x)) * self.w3(x)) |
| enable_profiling = false | ||
| save_traces_folder = "profile_trace" | ||
| profile_freq = 100 | ||
| profile_freq = 1000 |
| [compile] | ||
| enable=false | ||
| components = ["model", "loss"] | ||
| backend="inductor" |
There was a problem hiding this comment.
this is BC breaking, need to default it to None
stack-info: PR: #1768, branch: IvanKobzarev/stack/1
95810a2 to
78d053b
Compare
stack-info: PR: #1768, branch: IvanKobzarev/stack/1
78d053b to
3c5c12d
Compare
stack-info: PR: #1768, branch: IvanKobzarev/stack/1
3c5c12d to
5b96709
Compare
|
Hi @IvanKobzarev n00b questions about torch.compile - If the backend is none, which backend is being used? |
tianyu-l
left a comment
There was a problem hiding this comment.
sorry blocking because wanted to resolve a question before merge.
| if job_config.compile.backend is None: | ||
| model = torch.compile(model, fullgraph=True) | ||
| else: | ||
| model = torch.compile( | ||
| model, backend=job_config.compile.backend, fullgraph=True | ||
| ) |
There was a problem hiding this comment.
The config sounds good to me. I have a question regarding UX.
What's your thought on why having this if else branch?
If torch.compile's default backend doesn't change (assuming inductor), I think it's fine to set it as the default for job_config.compile.backend so that we only need to have the else branch (not the if).
There was a problem hiding this comment.
Yeah, originally I put "inductor" as a default value.
But this will not be BC in case when torch.compile switch default behavior.
So I put if/else to absolutely comply.
@ezyang wdyt about removing if/else with default value?
There was a problem hiding this comment.
But this will not be BC in case when torch.compile switch default behavior
why it's not BC if torch.compile switch default? I think in this case it would be torch.compile breaks BC, but torchtitan keeps BC.
There was a problem hiding this comment.
Ok, set "inductor" as default and removed if/else.
stack-info: PR: #1768, branch: IvanKobzarev/stack/1
5b96709 to
304d2a9
Compare
| default_factory=lambda: ["model", "loss"] | ||
| ) | ||
| """Which components to compile""" | ||
| backend: Optional[str] = None |
There was a problem hiding this comment.
TorchTitan doesn't use Optional.
| backend: Optional[str] = None | |
| backend: str | None = None |
stack-info: PR: pytorch#1768, branch: IvanKobzarev/stack/1
304d2a9 to
2cfec63
Compare
stack-info: PR: #1768, branch: IvanKobzarev/stack/1
2cfec63 to
663e47f
Compare
stack-info: PR: #1768, branch: IvanKobzarev/stack/1
663e47f to
164d3d6
Compare
fegin
left a comment
There was a problem hiding this comment.
LGTM, one nit, to make the code consistent with other function e.g., apply_ac, we should just pass the required config as mentioned in the comments.
|
|
||
|
|
||
| def apply_compile(model: nn.Module): | ||
| def apply_compile(model: nn.Module, job_config: JobConfig): |
There was a problem hiding this comment.
| def apply_compile(model: nn.Module, job_config: JobConfig): | |
| def apply_compile(model: nn.Module, compile_config: Compile): |
| # turn on per-TransformerBlock compile after AC wrapping and before FSDP | ||
| if model_compile_enabled: | ||
| apply_compile(model) | ||
| apply_compile(model, job_config) |
There was a problem hiding this comment.
| apply_compile(model, job_config) | |
| apply_compile(model, job_config.compile) |
| if job_config.compile.enable: | ||
| apply_compile(model) | ||
| apply_compile(model.encoder) | ||
| apply_compile(model, job_config) |
There was a problem hiding this comment.
| apply_compile(model, job_config) | |
| apply_compile(model, job_config.compile) |
| apply_compile(model) | ||
| apply_compile(model.encoder) | ||
| apply_compile(model, job_config) | ||
| apply_compile(model.encoder, job_config) |
There was a problem hiding this comment.
| apply_compile(model.encoder, job_config) | |
| apply_compile(model.encoder, job_config.compile) |
|
|
||
| if model_compile_enabled: | ||
| apply_compile(model) | ||
| apply_compile(model, job_config) |
There was a problem hiding this comment.
| apply_compile(model, job_config) | |
| apply_compile(model, job_config.compile) |
| # turn on per-TransformerBlock compile after AC wrapping and before FSDP | ||
| if model_compile_enabled: | ||
| apply_compile(model) | ||
| apply_compile(model, job_config) |
There was a problem hiding this comment.
| apply_compile(model, job_config) | |
| apply_compile(model, job_config.compile) |
|
|
||
|
|
||
| def apply_compile(model: nn.Module): | ||
| def apply_compile(model: nn.Module, job_config: JobConfig): |
There was a problem hiding this comment.
| def apply_compile(model: nn.Module, job_config: JobConfig): | |
| def apply_compile(model: nn.Module, compile_config: Compile): |
|
|
||
|
|
||
| def apply_compile(model: nn.Module): | ||
| def apply_compile(model: nn.Module, job_config: JobConfig): |
There was a problem hiding this comment.
Here we don't need to send in a JobConfig, we only need a backend str.
I'm also OK with sending in config: CompileConfig where we do
from torchtitan.config import Compile as CompileConfig
The latter is more future-proof but not necessary right now. Up to you.
stack-info: PR: #1768, branch: IvanKobzarev/stack/1
164d3d6 to
bd1d5c4
Compare
stack-info: PR: #1768, branch: IvanKobzarev/stack/1
bd1d5c4 to
6a37f3d
Compare
stack-info: PR: #1768, branch: IvanKobzarev/stack/1
6a37f3d to
e839c0d
Compare
Stacked PRs: * __->__#1768 --- --- --- ### config compile backend
Stacked PRs: * __->__#1768 --- --- --- ### config compile backend
Stacked PRs:
config compile backend