Repository navigation
feat/fix: address studio UI contrast, Windows encoding crashes, download confirmation, and DPOConfig deprecations - #6543
TheJagStudio wants to merge 6 commits into
Conversation
…nslothai#5125 Issue unslothai#4155 — DPO: add UnslothDPOConfig and update PatchDPOTrainer - unsloth/trainer.py: import trl.DPOConfig, expose UnslothDPOConfig subclass (falls back to TrainingArguments when trl<0.7); export via __all__ - unsloth/models/dpo.py: replace no-op PatchDPOTrainer with a patch that monkey-patches DPOTrainer.__init__ to emit a DeprecationWarning when legacy TrainingArguments is passed instead of DPOConfig; includes docstring example Issue unslothai#6469 — Code block readability in Unsloth Studio UI - studio/frontend/src/index.css: add #f3f4f6 background + subtle border for fenced code blocks in light mode (dark mode keeps #181818); add padding-right to code-block-header so the language label is never obscured by the absolute-positioned copy/download action buttons; add matching inline code surface for <code> spans Issue unslothai#6489 — UnicodeEncodeError (charmap codec) on Windows - studio/backend/main.py: reconfigure sys.stdout/stderr to utf-8 with errors=replace at process start, before any print (Windows only) - studio/backend/startup_banner.py: introduce _safe_print() that falls back to encode/replace on UnicodeEncodeError; use it for all banner output - studio/backend/core/training/trainer.py: add encoding='utf-8' to both open() calls on adapter_config.json - unsloth_cli/commands/chat.py: add encoding='utf-8' to adapter_config open - unsloth_cli/commands/studio.py: pass PYTHONIOENCODING=utf-8:replace in the child-process environment when spawning the backend on Windows; also add encoding='utf-8' to the auth-secret fdopen call Issue unslothai#5125 — Request permission before downloading model on first run - studio/backend/hub/schemas/downloads.py: add confirmed:bool=False field to DownloadModelRequest; add needs_confirmation:bool=False to DownloadStartResponse - studio/backend/hub/services/models/downloads.py: add _is_model_in_local_cache() helper that checks the HF cache; when confirmed=False and model is absent from cache, return state='confirmation_required' / needs_confirmation=True before spawning any download worker — the frontend can then show a dialog and re-POST with confirmed=True Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Claude-Session: https://claude.ai/code/session_016EuHUXBUpgszgrjtjL7ghp
There was a problem hiding this comment.
Code Review
This pull request introduces several improvements, including forcing UTF-8 encoding on Windows streams and file operations to prevent UnicodeEncodeErrors, implementing a download confirmation gate for non-cached models, adding frontend styling for code blocks, and patching TRL's DPOTrainer to support DPOConfig with backward compatibility. The reviewer recommended enhancing the DPOTrainer patch to detect deprecated TrainingArguments passed as positional arguments and to dynamically generate the warning message.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 50e9b4af72
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "state": "confirmation_required", | ||
| "accepted": False, | ||
| "generation": 0, | ||
| "needs_confirmation": True, |
There was a problem hiding this comment.
Add the client confirmation retry before rejecting downloads
The Studio client path still never sends the new confirmed field (startModelDownload only serializes the existing repo/variant/transport fields), and startJob treats any accepted: false response as a terminal error. In that current UI flow, every first-time model download reaches this confirmation_required response but no dialog/retry can ever be issued, so users just see a failed download and cannot start it from Studio.
Useful? React with 👍 / 👎.
| """Return True if *repo_id* (and optional GGUF *variant*) is already present | ||
| in the local HuggingFace cache so no network download is needed.""" | ||
| try: | ||
| scan = hf_cache_scan.scan_cache_dir() |
There was a problem hiding this comment.
Use the repo cache scanner API for the cache bypass
Here hf_cache_scan is the local hub.utils.inventory_scan module, which exposes all_hf_cache_scans() rather than scan_cache_dir(). This call raises AttributeError and is swallowed by the broad except, so _is_model_in_local_cache() always returns False; even models that are already cached are reported as needing confirmation, defeating the intended local-cache bypass.
Useful? React with 👍 / 👎.
Extracted and narrowed from unslothai#6543 by @TheJagStudio. This keeps the startup/banner and text file encoding hardening separate from the already-merged Python code-exec UTF-8 fix in unslothai#6548. Co-authored-by: Jagrat Patel <[email protected]>
Extracted and narrowed from #6543 by @TheJagStudio. This keeps the startup/banner and text file encoding hardening separate from the already-merged Python code-exec UTF-8 fix in #6548. Co-authored-by: Jagrat Patel <[email protected]>
|
The utf-8 encoding fixes and the code block contrast change look right, but the download confirmation gate lands backend-only: hub/utils/inventory_scan.py exposes no module-level scan_cache_dir, so _is_model_in_local_cache always falls into its except and returns False, and nothing in the frontend sends confirmed=true. As it stands every Hub download would come back confirmation_required and never start. Could you split this into separate PRs, fix that gate, and drop the DPOTrainer init monkeypatch which only adds a warning? |
|
Main now carries the Windows UTF-8 work in studio/backend/main.py and startup_banner.py via #6614, and the download gate still calls hf_cache_scan.scan_cache_dir, which hub/utils/inventory_scan.py does not define, so _is_model_in_local_cache always returns False and every Hub download would come back confirmation_required with no frontend sending confirmed=true. Could you rebase and narrow this to the index.css contrast fix, either dropping the download gate and the warning-only DPOTrainer init patch or moving them to their own PR? |
|
Thank you for the PR and for collecting these reports in one place! Closing this since every part is either already on main or no longer needed:
If you still see the remaining #6489 report (the charmap error in Data Recipe dataset generation), a focused PR for that path would be very welcome. |
Overview
This pull request introduces a cohesive set of fixes and feature improvements across the Unsloth backend, CLI, and Studio frontend. It comprehensively addresses recent community-reported issues ranging from environment-specific crashes to user experience enhancements in the local Studio interface.
Changes Breakdown
1. 🧯 Fix Windows UnicodeEncodeError crashes (Closes #6489)
sys.stdoutandsys.stderrstreams to forceutf-8handling (with replacement fallbacks) when running on Windows platforms. This prevents the startup banner (and the 🦥 emoji) from crashing on defaultcp1252terminals.encoding="utf-8"across file-read operations withintrainer.py,chat.py, and authentication utility writers.2. 🛡️ Add Confirmation Gate for First-Time Model Downloads (Closes #5125)
confirmedflag field toDownloadModelRequestand a correspondingneeds_confirmationproperty to the response schemas.hf_cache_scan. If a model isn't present locally and the request hasn't been explicitly pre-confirmed, the server safely responds with aconfirmation_requiredstate, allowing the frontend to present a storage-warning dialog before proceeding.3. 🎨 Improve Code Block Contrast & Readability in Studio UI (Closes #6469)
index.cssto implement a softer gray surface background for inline and fenced code styles in light mode, visually separating code snippets from standard chat bubbles.padding-right: 5rem;buffer on code-block headers to prevent language labels from sliding beneath the absolute-positioned copy/download action buttons on narrower layouts.4. 📦 Update DPO Trainer to support
DPOConfig(Closes #4155)DPOTrainer.__init__to gracefully accept nativetrl.DPOConfigarguments alongside a backward-compatible warning shim for legacyTrainingArguments.UnslothDPOConfigwithinunsloth/trainer.pyas a robust drop-in replacement that defaults to standardTrainingArgumentsif an older TRL version is installed.Verification & Testing
utf-8stream reconfiguration correctly guards againstUnicodeEncodeErroron Windows terminal contexts.