Skip to content

OpenVINO export: trust remote code only for a remote-code model, and decode the bounds probe as UTF-8 - #12012

Merged
danielhanchen merged 1 commit into
mainfrom
openvino-export-trust-and-utf8
Sep 26, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
openvino-export-trust-and-utf8

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

Two tests in Repo tests (CPU, rest) fail on main since #11907 (OpenVINO export). The job never ran on that PR before it merged; the org queue is backed up, so main has not run it either. Reproduced locally on 0657c177e, and both pass on the parent of #11907:

FAILED tests/saving/test_torchao_remote_code_consent.py::test_compressed_and_gguf_lora_paths_drop_auto_map_trust
    assert "_loaded_via_remote_code(model) or _loaded_via_remote_code(tokenizer)" not in _SRC
FAILED tests/saving/test_save_subprocess_utf8_encoding.py::test_save_subprocess_text_calls_declare_utf8_encoding
    Text-mode subprocess call(s) in unsloth/save.py missing encoding="utf-8" ... at line(s): 7008

Which side is wrong

Both tests are right; the new code breaks invariants they were written to hold.

  • Remote-code trust. _unsloth_save_openvino passed --trust-remote-code to optimum-cli export openvino when either the model or the tokenizer had been loaded through remote code. That one flag governs both the model and the tokenizer loads in the child. So an approved custom tokenizer switched on remote code for a model that loaded with built-in classes, and a checkpoint whose config carries an auto_map would then run that unvetted code during the reload. That is exactly the case the consent tests exist to stop; the torchao and compressed exports keep the two decisions separate for this reason.
  • Encoding. The optimum-intel bounds probe ran subprocess.run(..., text = True) without encoding, so on Windows its output is decoded as cp1252 ([Bug] UnicodeDecodeError on Windows due to missing encoding="utf-8" in open() call #2660). The probe's failures are swallowed, so there it would silently skip the bounds check rather than crash, but it is the pattern the drift check bans.

Fix

  • --trust-remote-code now follows the model's approved load decision, the same rule the GGUF-LoRA converter uses for its single flag. When only the tokenizer came from remote code, the export runs without the flag and warns that optimum may skip converting the tokenizer. An explicit trust_remote_code passed by the caller is still honored.
  • The probe pins encoding = "utf-8", errors = "replace", like the other text-mode calls in save.py.
  • New test_a_custom_tokenizer_alone_does_not_trust_the_model in tests/saving/test_openvino_export.py: a remote-code tokenizer with a built-in model gets no --trust-remote-code and one warning. The existing case (remote-code model gets the flag) is unchanged.

Verification

  • tests/saving/test_openvino_export.py, test_torchao_remote_code_consent.py, test_save_subprocess_utf8_encoding.py, test_export_api_surface.py: 40 passed, 1 skipped on this branch.
  • Against main's save.py, the two consent/encoding guards and the new test fail (3 failed).
  • Local full-suite differential, main 0657c177e vs e7edce154 (18 commits earlier), tests/ outside tests/studio: these two are the only failures that main has and the older tree does not, apart from an untracked unsloth_compiled_cache file the exec-literal lint picked up locally.

…decode the bounds probe as UTF-8

#11907 passed --trust-remote-code to optimum-cli when either the model or the tokenizer had been
loaded through remote code. The flag covers both loads, so an approved custom tokenizer let the
reload run a built-in-loaded model's unvetted auto_map code, which
test_compressed_and_gguf_lora_paths_drop_auto_map_trust forbids. The flag now follows the model,
as the GGUF-LoRA converter does, and a tokenizer-only case warns instead.

The optimum-intel bounds probe decoded its output in the locale encoding, which
test_save_subprocess_text_calls_declare_utf8_encoding forbids (#2660); it now pins utf-8.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-26T09:39:54.057639Z 5e01f48 Manual request
🔒 Security Review ⚠️ Failed 2026-09-26T09:38:19.542542Z 5e01f48 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 5e01f48cd6

ℹ️ 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".

@danielhanchen
danielhanchen merged commit ad3038b into main Sep 26, 2026
27 of 28 checks passed
@danielhanchen
danielhanchen deleted the openvino-export-trust-and-utf8 branch September 26, 2026 09:49
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…decode the bounds probe as UTF-8 (unslothai#12012)

unslothai#11907 passed --trust-remote-code to optimum-cli when either the model or the tokenizer had been
loaded through remote code. The flag covers both loads, so an approved custom tokenizer let the
reload run a built-in-loaded model's unvetted auto_map code, which
test_compressed_and_gguf_lora_paths_drop_auto_map_trust forbids. The flag now follows the model,
as the GGUF-LoRA converter does, and a tokenizer-only case warns instead.

The optimum-intel bounds probe decoded its output in the locale encoding, which
test_save_subprocess_text_calls_declare_utf8_encoding forbids (unslothai#2660); it now pins utf-8.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant