Skip to content

[Bug] Assigning HidePrintMessage(sys.stderr) to sys.stderr halts further execution in jupyter notebook #3745

Closed

Description

@janvdp
  1. latest release: 2025.12.6
  2. local - Jupyter Notebook
  3. not relevant
    4.https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_(0_6B)-Phone_Deployment.ipynb
  4. unsloth 2025.12.6
  5. not relevant

Description:

Running the:

from unsloth import FastLanguageModel
import torch

# Models supported for Phone Deployment
fourbit_models = [
    "unsloth/Qwen3-4B",              # Any Qwen3 model like 0.6B, 4B, 8B, 32B
    "unsloth/Qwen3-32B",
    "unsloth/Llama-3.1-8B-Instruct", # Llama 3 models work
    "unsloth/Llama-3.3-70B-Instruct",
    "unsloth/gemma-3-270m-it",       # Gemma 3 models work
    "unsloth/gemma-3-27b-it",
    "unsloth/Qwen2.5-7B-Instruct",   # And more models!
    "unsloth/Phi-4-mini-instruct",
] # More models at https://huggingface.co/unsloth

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "unsloth/Qwen3-0.6B",
    max_seq_length = 1024,
    full_finetuning = True,
    qat_scheme = "phone-deployment", # Flag for phone deployment
)

prevents next cells from running, as it results in an error:

[IPKernelApp] ERROR | Exception in message handler:
Traceback (most recent call last):
  File "/opt/conda/lib/python3.11/site-packages/ipykernel/kernelbase.py", line 471, in dispatch_shell
    await result
  File "/opt/conda/lib/python3.11/site-packages/ipykernel/ipkernel.py", line 366, in execute_request
    await super().execute_request(stream, ident, parent)
  File "/opt/conda/lib/python3.11/site-packages/ipykernel/kernelbase.py", line 827, in execute_request
    reply_content = await reply_content
                    ^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/ipykernel/ipkernel.py", line 458, in do_execute
    res = shell.run_cell(
          ^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/ipykernel/zmqshell.py", line 663, in run_cell
    return super().run_cell(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/IPython/core/interactiveshell.py", line 3114, in run_cell
    with self._tee(channel="stdout"), self._tee(channel="stderr"):
  File "/opt/conda/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/IPython/core/interactiveshell.py", line 3073, in _tee
    stream.write = write
    ^^^^^^^^^^^^
AttributeError: 'HidePrintMessage' object attribute 'write' is read-only

The problem

in unsloth/import_fixes.py

if os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") != "1":
    import sys

    # Apply to stderr for FBGEMM
    sys.stderr = HidePrintMessage(sys.stderr)  # <<--- This line causes the error and prevents all other cells from running.

Work around for me

Comment the sys.stderr assignment:

if os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") != "1":
    import sys

    # Apply to stderr for FBGEMM
    #sys.stderr = HidePrintMessage(sys.stderr)

Activity

  1. wektorz commented on Dec 18, 2025

    @wektorz

    run into this too, in mainly vllm script that imports unloth too, for me the workaround required more comented out

    # Apply to stderr for FBGEMM
        # sys.stderr = HidePrintMessage(sys.stderr)
        # https://github.com/pytorch/FBGEMM/blob/d99cd96490ec4aabac2ee95b1e76ea4dcfcfa628/fbgemm_gpu/experimental/gemm/triton_gemm/utils.py#L43-L52
        # sys.stderr.add_filter("TMA benchmarks will be running")
    
    
  2. Datta0 commented on Dec 19, 2025

    @Datta0
    Contributor

    Hey @wektorz @nikitml Thanks for noticing this and raising an issue. I'll immediately check on this

  3. Datta0 commented on Dec 19, 2025

    @Datta0
    Contributor

    Hey @wektorz @nikitml
    I just pushed a fix to my repo here
    Do you guys mind giving it a try on your end to see if things work fine? I Just tested on jupyter notebook as well as python script on my VM and also on Colab T4, it seems to work fine.

    To install, you need to do

    ! pip uninstall unsloth 
    ! pip install git+https://github.com/datta0/unsloth.git@tma_sys_fix --no-deps
    

    it'd be of great help if you can confirm whether this works

  4. nikitml commented on Dec 19, 2025

    @nikitml

    Worked for me so far! Thank you for such a reactive fix

  5. self-assigned this
    on Dec 19, 2025
  6. Datta0 commented on Dec 19, 2025

    @Datta0
    Contributor

    I will inform Daniel to create a new pypi package tomorrow. Sorry for the inconveniences caused :)
    Thanks for promptly testing :)

  7. danielhanchen commented on Dec 20, 2025

    @danielhanchen
    Member

    @janvdp @nikitml @wektorz Much apologies on the issue - we just did a new pip release - please try if it works thank you! pip install --upgrade --force-reinstall --no-deps --no-cache-dir unsloth

  8. added
    fixed - pending confirmation
    and removed
    currently fixing
    on Dec 20, 2025
  9. janvdp commented on Dec 20, 2025

    @janvdp
    Author

    @danielhanchen just tested on unsloth:2025.12.8 and seems to be working fine! Awesome support!

  10. Datta0 commented on Dec 22, 2025

    @Datta0
    Contributor

    Closing this as it has been confirmed to work. Feel free to drop a comment if you need further assistance

  11. added
    fixed
    and removed
    fixed - pending confirmation
    on Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugfixed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions