Skip to content

Commit 714ec9a

Browse files
authored
Allow configuring pytorch compilation mode (#905)
This PR allows users to configure the compilation mode used by `Pi0Pytorch` to compile the `sample_actions` method. This was specifically motivated by needing to use the `max-autotune-no-cudagraphs` mode, due to threading issues. By default the compilation mode is `max-autotune`, which preserves existing behavior.
2 parents 37ea668 + 417042a commit 714ec9a

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/openpi/models/pi0_config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,20 @@ class Pi0Config(_model.BaseModelConfig):
3232
# This config option is not used directly by the model, but it is read by the ModelTransformFactory.
3333
discrete_state_input: bool = None # type: ignore
3434

35+
pytorch_compile_mode: str | None = "max-autotune"
36+
3537
def __post_init__(self):
3638
if self.max_token_len is None:
3739
object.__setattr__(self, "max_token_len", 200 if self.pi05 else 48)
3840
if self.discrete_state_input is None:
3941
object.__setattr__(self, "discrete_state_input", self.pi05)
42+
if self.pytorch_compile_mode is not None:
43+
assert self.pytorch_compile_mode in [
44+
"default",
45+
"reduce-overhead",
46+
"max-autotune",
47+
"max-autotune-no-cudagraphs",
48+
]
4049

4150
@property
4251
@override

src/openpi/models_pytorch/pi0_pytorch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def __init__(self, config):
109109
self.action_time_mlp_out = nn.Linear(action_expert_config.width, action_expert_config.width)
110110

111111
torch.set_float32_matmul_precision("high")
112-
self.sample_actions = torch.compile(self.sample_actions, mode="max-autotune")
112+
if config.pytorch_compile_mode is not None:
113+
self.sample_actions = torch.compile(self.sample_actions, mode=config.pytorch_compile_mode)
113114

114115
# Initialize gradient checkpointing flag
115116
self.gradient_checkpointing_enabled = False

0 commit comments

Comments
 (0)