Skip to content

Commit fa6c212

Browse files
committed
Fix lint: revert torchrun shutil.which, remove unused imports, ruff format
The torchrun-not-found issue was caused by the venv not being activated, not an installation problem. Revert to plain 'torchrun' command. Remove now-unused shutil and sys imports. Run ruff format on all modified files.
1 parent fa53865 commit fa6c212

5 files changed

Lines changed: 14 additions & 25 deletions

File tree

src/instructlab/training/gpt_oss_utils_correct.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,11 @@ def is_known_model(
416416
# convert to config
417417
model_config = model_path_or_config
418418
if isinstance(model_path_or_config, str):
419-
_trust_remote = os.environ.get(
420-
"TRUST_REMOTE_CODE", ""
421-
).lower() in ("1", "true", "yes")
419+
_trust_remote = os.environ.get("TRUST_REMOTE_CODE", "").lower() in (
420+
"1",
421+
"true",
422+
"yes",
423+
)
422424
model_config = AutoConfig.from_pretrained(
423425
model_path_or_config, trust_remote_code=_trust_remote
424426
)

src/instructlab/training/main_ds.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import datetime
66
import logging
77
import os
8-
import shutil
98
import subprocess
10-
import sys
119
import time
1210
import warnings
1311

@@ -638,15 +636,8 @@ def run_training(torch_args: TorchrunArgs, train_args: TrainingArgs) -> None:
638636
os.makedirs(train_args.ckpt_output_dir, exist_ok=True)
639637

640638
# build distributed training command
641-
torchrun_path = shutil.which("torchrun")
642-
if not torchrun_path:
643-
raise RuntimeError(
644-
"torchrun executable not found in PATH. "
645-
"Ensure PyTorch is installed correctly."
646-
)
647-
648639
command = [
649-
torchrun_path,
640+
"torchrun",
650641
f"--nproc-per-node={torch_args.nproc_per_node}",
651642
f"--nnodes={torch_args.nnodes}",
652643
f"--node-rank={torch_args.node_rank}",

src/instructlab/training/model.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -615,13 +615,9 @@ def __init__(
615615
lora_quant_bits=lora_quant_bits,
616616
trust_remote_code=trust_remote_code,
617617
)
618-
if is_vlm_with_causal_lm(
619-
model_path, trust_remote_code=trust_remote_code
620-
):
618+
if is_vlm_with_causal_lm(model_path, trust_remote_code=trust_remote_code):
621619
self.model = extract_causal_lm_from_vlm(model_path, self.base_model_args)
622-
elif is_vlm_for_direct_loading(
623-
model_path, trust_remote_code=trust_remote_code
624-
):
620+
elif is_vlm_for_direct_loading(model_path, trust_remote_code=trust_remote_code):
625621
self.model = load_vlm_for_text_training(model_path, self.base_model_args)
626622
else:
627623
self.model = AutoModelForCausalLM.from_pretrained(**self.base_model_args)

src/instructlab/training/tokenizer_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ def setup_tokenizer(
9898
model_name_or_path,
9999
chat_tmpl_path: str | None = None,
100100
) -> PreTrainedTokenizer:
101-
trust_remote_code = os.environ.get(
102-
"TRUST_REMOTE_CODE", ""
103-
).lower() in ("1", "true", "yes")
101+
trust_remote_code = os.environ.get("TRUST_REMOTE_CODE", "").lower() in (
102+
"1",
103+
"true",
104+
"yes",
105+
)
104106
tokenizer = AutoTokenizer.from_pretrained(
105107
model_name_or_path, trust_remote_code=trust_remote_code
106108
)

tests/unit/test_pretraining_mode.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ def encode(self, text, add_special_tokens=True):
138138
num_cpu_procs=1,
139139
)
140140

141-
mock_auto.assert_called_once_with(
142-
"stub-model", trust_remote_code=False
143-
)
141+
mock_auto.assert_called_once_with("stub-model", trust_remote_code=False)
144142

145143
output_file = output_dir / "data.jsonl"
146144
self.assertTrue(output_file.exists())

0 commit comments

Comments
 (0)