Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

CLI: let train load models that need trust_remote_code (#16332)

Yakshith3435afe1c54e
diff --git a/unsloth_cli/commands/train.py b/unsloth_cli/commands/train.py
index cedb299802b..c180d1bf548 100644
--- a/unsloth_cli/commands/train.py
+++ b/unsloth_cli/commands/train.py
@@ -394,6 +394,7 @@ def train(
hf_token = hf_token,
is_dataset_image = is_dataset_image,
is_dataset_audio = is_dataset_audio,
+ trust_remote_code = cfg.training.trust_remote_code,
use_gradient_checkpointing = cfg.training.gradient_checkpointing,
):
typer.echo("Model load failed", err = True)
diff --git a/unsloth_cli/config.py b/unsloth_cli/config.py
index 48e69ee8735..f5f069cee2c 100644
--- a/unsloth_cli/config.py
+++ b/unsloth_cli/config.py
@@ -29,6 +29,7 @@ class TrainingConfig(BaseModel):
training_type: Literal["lora", "full"] = "lora"
max_seq_length: int = 2048
load_in_4bit: bool = True
+ trust_remote_code: bool = False
output_dir: Path = Path("./outputs")
num_epochs: int = 3
learning_rate: float = 2e-4
diff --git a/unsloth_cli/tests/test_train_trust_remote_code.py b/unsloth_cli/tests/test_train_trust_remote_code.py
new file mode 100644
index 00000000000..7055f2f7aee
--- /dev/null
+++ b/unsloth_cli/tests/test_train_trust_remote_code.py
@@ -0,0 +1,73 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+from types import SimpleNamespace
+
+import pytest
+import typer
+from typer.testing import CliRunner
+
+_REPO_ROOT = Path(__file__).resolve().parents[2]
+if str(_REPO_ROOT) not in sys.path:
+ sys.path.insert(0, str(_REPO_ROOT))
+
+import unsloth_cli.commands.train as train_module # noqa: E402
+
+
+class _RecordingTrainer:
+ is_vlm = False
+ training_thread = None
+
+ def __init__(self):
+ self.load_kwargs = None
+
+ def load_model(self, **kwargs):
+ self.load_kwargs = kwargs
+ return True
+
+ def prepare_model_for_training(self, **kwargs):
+ return True
+
+ def load_and_format_dataset(self, **kwargs):
+ return [], None
+
+ def start_training(self, **kwargs):
+ return True
+
+ def get_training_progress(self):
+ return SimpleNamespace(error = None, is_completed = True)
+
+
+ "yaml_extra, argv, expected",
+ [
+ ("", [], False),
+ ("", ["--trust-remote-code"], True),
+ ("training:\n trust_remote_code: true\n", [], True),
+ ("training:\n trust_remote_code: true\n", ["--no-trust-remote-code"], False),
+ ],
+)
+def test_train_forwards_trust_remote_code_to_load_model(
+ tmp_path, monkeypatch, yaml_extra, argv, expected
+):
+ config = tmp_path / "config.yaml"
+ config.write_text(
+ "model: org/custom-code-model\ndata:\n dataset: yahma/alpaca-cleaned\n" + yaml_extra,
+ encoding = "utf-8",
+ )
+ trainer = _RecordingTrainer()
+ monkeypatch.setattr(train_module, "_create_cli_trainer", lambda *args: trainer)
+ monkeypatch.setattr(
+ train_module, "_dataset_modalities", lambda *args: (False, False), raising = False
+ )
+ app = typer.Typer()
+ app.command()(train_module.train)
+
+ result = CliRunner().invoke(app, ["--config", str(config), *argv])
+
+ assert result.exit_code == 0, result.output
+ assert trainer.load_kwargs["trust_remote_code"] is expected