Skip to content

Commit ff8ad7a

Browse files
Merge pull request #117 from drunkenbot-ai/develop
fix triton related issue
2 parents 57f8375 + 61e2d56 commit ff8ad7a

6 files changed

Lines changed: 50 additions & 1 deletion

File tree

engine

interface/core/project_state.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def _default_project_state(self) -> dict[str, Any]:
101101
"data_loader_workers": 0,
102102
"max_grad_norm": 1.0,
103103
"activation_checkpointing": False,
104+
"compile_model": False,
104105
"seed": 1337,
105106
"device": self.device.currentText(),
106107
"use_amp": self.use_amp_default,
@@ -350,6 +351,7 @@ def _project_state_dict(self, project_name: str, project_dir: Path) -> dict[str,
350351
"data_loader_workers": self.data_loader_workers.value(),
351352
"max_grad_norm": self.max_grad_norm.value(),
352353
"activation_checkpointing": self.activation_checkpointing.isChecked(),
354+
"compile_model": self.compile_model.isChecked() if hasattr(self, "compile_model") else False,
353355
"seed": self.seed.value(),
354356
"device": self.device.currentText(),
355357
"use_amp": self.use_amp.isChecked(),

interface/core/project_state_apply.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ def _apply_project_state(self, data: dict[str, Any]) -> None:
171171
self.data_loader_workers.setValue(int(training.get("data_loader_workers", self.data_loader_workers.value())))
172172
self.max_grad_norm.setValue(float(training.get("max_grad_norm", self.max_grad_norm.value())))
173173
self.activation_checkpointing.setChecked(bool(training.get("activation_checkpointing", False)))
174+
if hasattr(self, "compile_model"):
175+
self.compile_model.setChecked(bool(training.get("compile_model", False)))
174176
self.seed.setValue(int(training.get("seed", self.seed.value())))
175177
self._set_combo_text(self.device, str(training.get("device", self.device.currentText())))
176178
self.use_amp.setChecked(bool(training.get("use_amp", self.use_amp.isChecked())))

interface/screens/training_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def _current_training_config(
6767
data_loader_workers=self.data_loader_workers.value(),
6868
max_grad_norm=self.max_grad_norm.value(),
6969
activation_checkpointing=self.activation_checkpointing.isChecked(),
70+
compile_model=self.compile_model.isChecked() if hasattr(self, "compile_model") else False,
7071
device=self.device.currentText(),
7172
use_amp=self.use_amp.isChecked(),
7273
precision=self._precision_value(),

interface/tabs/training_tab.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ def build_training_tab(window) -> QWidget:
195195
window.activation_checkpointing,
196196
"Recompute transformer activations during backpropagation to lower VRAM use. Training becomes slower, but this is useful when memory is the constraint.",
197197
)
198+
window.compile_model = QCheckBox("Torch compile")
199+
window.compile_model.setChecked(False)
200+
window._tip(
201+
window.compile_model,
202+
"Compile model using PyTorch Inductor for kernel fusion. Requires supported CUDA environment and Triton.",
203+
)
198204
window.seed = window._spin(1, 2_147_483_647, 1337)
199205
window._tip(window.seed, "Random seed for reproducible initialization and sampling order.")
200206
window.device = QComboBox()
@@ -263,6 +269,7 @@ def build_training_tab(window) -> QWidget:
263269
right.addRow("CPU workers", window.data_loader_workers)
264270
right.addRow("Max grad", window.max_grad_norm)
265271
right.addRow("VRAM saver", window.activation_checkpointing)
272+
right.addRow("Kernel fusion", window.compile_model)
266273
right.addRow("Seed", window.seed)
267274
runtime = QFormLayout()
268275
window._configure_form(runtime)

tests/test_compile_model.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from __future__ import annotations
2+
3+
import unittest
4+
from pathlib import Path
5+
from unittest.mock import MagicMock, patch
6+
7+
import torch
8+
9+
from engine.config import ModelConfig, TrainingConfig
10+
from engine.training_impl import _try_compile_model
11+
12+
13+
class CompileModelTests(unittest.TestCase):
14+
def test_compile_model_defaults_to_false(self) -> None:
15+
config = TrainingConfig(output_dir=Path("tmp"))
16+
self.assertFalse(config.compile_model)
17+
18+
def test_try_compile_model_returns_eager_when_disabled(self) -> None:
19+
model = torch.nn.Linear(10, 10)
20+
compiled = _try_compile_model(model, "cuda", enabled=False)
21+
self.assertIs(compiled, model)
22+
23+
def test_try_compile_model_skips_on_cpu(self) -> None:
24+
model = torch.nn.Linear(10, 10)
25+
compiled = _try_compile_model(model, "cpu", enabled=True)
26+
self.assertIs(compiled, model)
27+
28+
@patch("torch.compile", side_effect=RuntimeError("Inductor compiler error"))
29+
def test_try_compile_model_catches_compiler_error_and_falls_back(self, _mock_compile) -> None:
30+
model = torch.nn.Linear(10, 10)
31+
with patch("torch.cuda.is_available", return_value=True):
32+
compiled = _try_compile_model(model, "cuda", enabled=True)
33+
self.assertIs(compiled, model)
34+
35+
36+
if __name__ == "__main__":
37+
unittest.main()

0 commit comments

Comments
 (0)