Skip to content

tmax: decode taxonomy.json and template_prompt.md as UTF-8 - #141

Open
KNambiarDJsc wants to merge 1 commit into
huggingface:mainfrom
KNambiarDJsc:fix/tmax-sampler-utf8
Open

KNambiarDJsc wants to merge 1 commit into
huggingface:mainfrom
KNambiarDJsc:fix/tmax-sampler-utf8

Conversation

@KNambiarDJsc

Copy link
Copy Markdown
Contributor

Summary

Another item from the #130 Windows-portability triage: tmax.sampler.template_prompt() reads two package data files via importlib.resources.files(...).read_text() with no explicit encoding, so Python falls back to the locale's preferred encoding — cp1252 on Windows, not UTF-8. template_prompt.md's prose contains bytes cp1252 can't decode (a right single quotation mark, byte 0x9d), so every call crashes:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2918: character maps to <undefined>

This is the same bug class fixed in #115 (locale-default text decoding), but a different call shape — importlib.resources.files().read_text() rather than subprocess(text=True, ...) — so it was outside that PR's scope and got missed.

Scoped narrowly to the two calls in this function; a repo-wide sweep of every .read_text()/.write_text() call is a much bigger, separate change and most of those sites only ever round-trip the tool's own generated JSON/TOML (never non-ASCII prose), so they're not exhibiting this failure mode.

Test plan

  • uv run pytest tests/test_tmax_recipe.py::test_taxonomy_sampling_is_repeatable_and_preserves_legacy_axes -q — now passes (was failing with UnicodeDecodeError on Windows)
  • uv run ruff check / ruff format --check on the touched file

Both are read via importlib.resources.files(...).read_text() with no
explicit encoding, so Python falls back to the locale's preferred
encoding. On Windows that's cp1252, not UTF-8, and
template_prompt.md's prose contains bytes cp1252 can't map (e.g. a
right single quotation mark), crashing every call with
UnicodeDecodeError. Same bug class as huggingface#115, different call shape
(importlib.resources vs subprocess) so outside that PR's scope.
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