training: restore YAML fallback for trust_remote_code (no UI toggle)

This commit is contained in:
Roland Tannous 2026-03-09 13:10:24 +00:00
commit f416b7aa3d
2 changed files with 12 additions and 13 deletions

View file

@ -199,19 +199,6 @@ def run_training_process(
event_queue.put({"type": "complete", "output_dir": None, "ts": time.time()})
else:
error_msg = trainer.training_progress.error or "Failed to load model"
# Hint about trust_remote_code if YAML says this model needs it
if not config.get("trust_remote_code", False):
try:
from utils.models.model_config import load_model_defaults
model_defaults = load_model_defaults(model_name)
yaml_trust = model_defaults.get("training", {}).get("trust_remote_code", False)
if yaml_trust:
error_msg = (
f"Model '{model_name}' requires trust_remote_code to be enabled. "
f"Please enable 'Trust remote code' in Chat Settings and try again."
)
except Exception:
pass
event_queue.put({
"type": "error",
"error": error_msg,

View file

@ -19,12 +19,14 @@ if str(backend_path) not in sys.path:
# Import backend functions
try:
from core.training import get_training_backend
from utils.models.model_config import load_model_defaults
except ImportError:
# Fallback: try to import from parent directory
parent_backend = backend_path.parent / "backend"
if str(parent_backend) not in sys.path:
sys.path.insert(0, str(parent_backend))
from core.training import get_training_backend
from utils.models.model_config import load_model_defaults
# Auth
from auth.authentication import get_current_subject
@ -194,6 +196,16 @@ async def start_training(
"trust_remote_code": request.trust_remote_code,
}
# Training page has no trust_remote_code toggle — the value comes from
# YAML model defaults applied when the user selects a model. As a safety
# net, consult the YAML directly so models that need it always get it.
if not training_kwargs["trust_remote_code"]:
model_defaults = load_model_defaults(request.model_name)
yaml_trust = model_defaults.get("training", {}).get("trust_remote_code", False)
if yaml_trust:
logger.info(f"YAML config sets trust_remote_code=True for {request.model_name}")
training_kwargs["trust_remote_code"] = True
# Free GPU memory: shut down any running inference/export subprocesses
# before training starts (they'd compete for VRAM otherwise)
try: