Repository navigation
Read and write text files as UTF-8 in tests - #7764
Merged
Merged
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
1 task done
This was referenced Oct 19, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes the tests read and write every text file as UTF-8, instead of relying on the platform's default encoding.
Follow-up to #7755, which did the same for the library, examples and scripts.
Motivation
Python's default text encoding depends on the platform until Python 3.15 (PEP 686): on Windows it is the ANSI code page (e.g.
cp1252), and on Linux it follows the locale.test_examples_index.pyreadsdocs/source/example_overview.md, which contains non-ASCII characters (…,🤗), so it depends on that default. This already fails on Linux CI: torch 2.6.0 ships NVRTC 12.4, which can leave an xdist worker's locale asC(#7720), and the read then raisesUnicodeDecodeError: 'ascii' codec can't decode byte 0xe2. The failure depends on which xdist worker the test lands on, so it is not deterministic. It failed in the minimum-versions job of #7741 (https://github.com/huggingface/trl/actions/runs/38909894519/job/117002780666) and earlier of #7642. The other reads and writes in the tests handle ASCII content today, and are changed for consistency with #7755.Changes
encoding="utf-8"to the text reads and writes in the tests: example index, CLI and config parsing, callbacks, SFT and Reward chat template checks, async GRPO and async distillation rollout state, Harbor task files, and the invariant trajectoriesNote
Low Risk
Test-only encoding annotations with no runtime or library behavior changes.
Overview
Tests now explicitly use UTF-8 for text file I/O instead of the platform default encoding, matching the library change in #7755.
open(),Path.read_text(),Path.write_text(), andNamedTemporaryFilecalls across the test suite passencoding="utf-8"when reading or writing JSON, YAML, markdown, chat templates, Harbor task fixtures, rollout checkpoint state, invariant trajectories, and W&B completion logs. No production code changes—behavior is unchanged on typical Linux UTF-8 setups; on Windows or non-UTF-8 locales, tests that touch non-ASCII docs (e.g.example_overview.md) become reliable.Reviewed by Cursor Bugbot for commit afb7347. Bugbot is set up for automated code reviews on this repo. Configure here.