Skip to content

UnicodeEncodeError (charmap codec) on Windows in Unsloth Studio / DiffusionGemma #6489

Closed
unslothai/unsloth-zoo
#797

Description

@RogerNavelsaker

Bug Report: UnicodeEncodeError (charmap codec) on Windows in Unsloth Studio

Problem Description

When running Unsloth Studio on Windows, if a chat prompt, system prompt, or template contains non-ASCII Unicode characters (such as the right arrow symbol → / \u2192, which is common in many chat templates), the inference process crashes immediately with a Python encoding error:

[engine error: 'charmap' codec can't encode character '\u2192' in position 3140: character maps to <undefined>]

This error is generated by the unsloth_zoo.diffusion_studio.shim server process and returned to the client as an assistant response block.


Root Cause

On Windows, Python's built-in open() function and the subprocess.Popen(..., text=True) interface default to the system's preferred ANSI code page (typically cp1252 or another charmap encoding depending on the system locale), rather than UTF-8.

There are three places in the Unsloth Studio backend where this triggers crashes:

  1. visual_engine.py — File I/O encoding:
    In visual_engine.py, the request file used to communicate with the child process (VisualServer) is written using open(self.req, "w") without specifying an encoding.
  2. visual_engine.py — Subprocess Pipe encoding:
    The VisualServer subprocess (llama-diffusion-gemma-visual-server) is spawned with text=True but no encoding, causing stdout decoding crashes when the child process outputs Unicode characters.
  3. shim.py — Template loader encoding:
    The canvas player HTML template is loaded via open(_PLAYER_TEMPLATE).read() without specifying an encoding.

Proposed Fix / PR

I have submitted a Pull Request fixing these Windows I/O encoding issues in the unsloth-zoo repository here:
unslothai/unsloth-zoo#797

Activity

  1. ekinnee commented on Jul 26, 2026

    @ekinnee

    Seeing the same type of error with an emoji. also on Windows:
    Error generating dataset: 'charmap' codec can't encode character '\U0001f60e' in position 2582: character maps to <undefined>

  2. danielhanchen commented on Oct 11, 2026

    @danielhanchen
    Member

    Fixed! Sorry on the delay. The request file write that raised this was fixed earlier in unslothai/unsloth-zoo#864, and the remaining part (DiffusionGemma replies with umlauts, arrows, emoji or CJK coming back garbled on Windows because the server output was decoded with the Windows code page) is fixed in unslothai/unsloth-zoo#797. It will be in the next release.
    To update: Unsloth Desktop will have an update banner. For Studio, use unsloth studio update. For Docker, use docker exec <container> unsloth-studio-update. Reopen if it still happens.

  3. added a commit that references this issue on Oct 11, 2026
    8f02662
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions