Skip to content

Unable to generate output with Gemma4 e2b on Windows, despite successful execution and training #13696

Closed

Description

@sakana-max

I am using machine translation from Japanese.
#7055
#13388

I have confirmed that the execution and training issues for Gemma4 e2b have been fixed; however, generating output using GGUF or merged models results in the error shown below. The recommended solution is to set the offload option to "Auto," but while this setting exists in the Training tab, I cannot find it in the Output tab. Please fix this.

Environment

Where are you using Unsloth?

  • [ Here] Unsloth desktop application
  • Unsloth web UI (unsloth studio)
  • Unsloth CLI
  • Python package or notebook
  • Colab or Kaggle

Operating system and version:
I use Windows

GPU model(s) and accelerator backend:

RTX4060ti in NVIDIA CUDA

Versions:

v0.1.907-beta 2026.10.5

What happened?

Steps to reproduce:

1.Export the trained Gemma4 e2b in either merged or GGUF format on a Windows machine equipped with approximately 8 GB of VRAM.
Expected behavior:
It is supposed to share VRAM and RAM for output.

Actual behavior:
The following error occurs, and it does not work.
Model and operation involved:

Output the Gemma-4e2b model fine-tuned using Unsloth Desktop.

Diagnostics and logs

Desktop application

Text copied from the error pop-up

Failed to load checkpoint: Unsloth: unsloth/gemma-4-E2B-it-unsloth-bnb-4bit does not fit in GPU memory (cuda:0 has 6.84 GB free), so transformers placed part of it on the CPU, which bitsandbytes cannot quantize. Pass `offload_layers = "auto"` to from_pretrained to keep the decoder layers the GPU cannot hold in host RAM and stream them in during training (slower, and it needs that much free system RAM), load a smaller model, or free GPU memory held by other programs.

Additional context

I apologize for contacting you repeatedly, but I would like to request a correction.

Activity

  1. added
    feature request
    on Oct 14, 2026
  2. GANESHPARDESHI07 commented on Oct 14, 2026

    @GANESHPARDESHI07

    I read your issue and listed some points to be checked before running the model

    1. In your Windows system --> Go to Windows PowerShell ---> type nvidia-smi ---> see the actual VRAM left in your system
    2. If the VRAM displays a good amount of space to run the Gemma-4e2b model, then check the connection, as you have not mentioned whether the GPU is integrated or using a GPU server
    3. If all is checked successfully, then just run a small quantized model with the same dataset using QLoRA and keep the context length =512 instead, and for fewer steps, see if it is running and can be exported
      If nothing works, try commenting -- will find the solution :)
  3. sakana-max commented on Oct 14, 2026

    @sakana-max
    Author

    I ran nvidia-smi.
    The available memory is 1073 MiB / 8188 MiB.
    Indeed, it would not be possible to fit everything into VRAM.
    However, regarding the goal of exporting the model, I believe the intended behavior is to share the model between VRAM and RAM.

  4. GANESHPARDESHI07 commented on Oct 14, 2026

    @GANESHPARDESHI07

    Okay, check available system RAM and whether another process is consuming most of your GPU memory.
    If not solved, then close GPU-consuming applications, restart the studio, and try using a smaller model
    Even I have investigated that automatic offloading during model loading is not the same as offloading during export.

  5. sakana-max commented on Oct 14, 2026

    @sakana-max
    Author

    Understood. The system is equipped with approximately 96 GB of RAM, with about 80 GB available for use.

    When I invoked the Unsloth Python virtual environment and ran the export using Python code configured with offload_layers="auto", the export completed successfully. Therefore, wouldn't the issue be resolved by adding an option to select offload_layers to the UnslothDesktop export UI? I developed the specific code in consultation with Gemini. It is quite an unusual piece of code, as—in addition to applying offload_layers="auto"—it includes a fix for a bug where the system would incorrectly report insufficient space on the C drive even though the output destination was the G drive. I have attached it below. ```

    import os
    
    # 1. キャッシュと一時フォルダをすべて G:\ に固定(さっきDLした10.2GBをそのまま再利用します)
    os.environ["HF_HOME"] = r"G:\unsloth_temp\hf_cache"
    os.environ["TMP"] = r"G:\unsloth_temp\tmp"
    os.environ["TEMP"] = r"G:\unsloth_temp\tmp"
    os.environ["TMPDIR"] = r"G:\unsloth_temp\tmp"
    os.environ["HF_HUB_DISABLE_SYMLINKS_WARNING"] = "1"
    
    os.makedirs(r"G:\unsloth_temp\hf_cache", exist_ok=True)
    os.makedirs(r"G:\unsloth_temp\tmp", exist_ok=True)
    
    # 2. tempfileモジュールがCドライブを見に行かないよう内部変数も強制固定
    import tempfile
    tempfile.tempdir = r"G:\unsloth_temp\tmp"
    
    # 3. 【最強の封印】Unslothのお節介なディスク容量チェックを完全に黙らせる(常に空き10TBと返答)
    import shutil
    from collections import namedtuple
    _FakeUsage = namedtuple("usage", ["total", "used", "free"])
    shutil.disk_usage = lambda path: _FakeUsage(20 * 1024**4, 10 * 1024**4, 10 * 1024**4)
    
    try:
        import psutil
        _FakePsUsage = namedtuple("sdiskusage", ["total", "used", "free", "percent"])
        psutil.disk_usage = lambda path: _FakePsUsage(20 * 1024**4, 10 * 1024**4, 10 * 1024**4, 50.0)
    except ImportError:
        pass
    
    # --- ここから Unsloth の読み込み ---
    from pathlib import Path
    from unsloth import FastLanguageModel
    import unsloth_zoo.saving_utils as su
    
    # 万が一 unsloth_zoo が直接参照を持っていても上書き
    if hasattr(su, "shutil"):
        su.shutil.disk_usage = shutil.disk_usage
    if hasattr(su, "psutil"):
        su.psutil.disk_usage = psutil.disk_usage
    
    # 4. チェックポイントの特定
    base_dir = Path(r"C:\Users\tatet\.unsloth\studio\outputs\unsloth_gemma-4-E2B-it_1791966512")
    adapter_files = sorted(
        base_dir.rglob("adapter_config.json"),
        key=lambda p: p.stat().st_mtime,
        reverse=True
    )
    checkpoint_dir = str(adapter_files[0].parent)
    print(f"✅ 読み込むチェックポイント: {checkpoint_dir}")
    
    # 5. 出力先(G:\ ドライブ)
    output_dir = r"G:\gemma-4-e2b-jp-coding"
    
    # 6. モデルのロード
    model, tokenizer = FastLanguageModel.from_pretrained(
        model_name = checkpoint_dir,
        max_seq_length = 2048,
        load_in_4bit = True,
        offload_layers = "auto",
    )
    
    # 7. GGUFへ変換(さっきの10.2GBキャッシュが使われるので爆速で進みます!)
    model.save_pretrained_gguf(
        output_dir,
        tokenizer,
        quantization_method = "q8_0",
    )
    
    print(f"🎉 今度こそ完全勝利! {output_dir} を確認してください!")
    
  6. indrajeetapache commented on Oct 14, 2026

    @indrajeetapache
    Contributor

    What’s going wrong

    Valid Studio/Desktop gap on low-VRAM export (here: Gemma-4 E2B on Windows ~8 GB, ~1 GB free in nvidia-smi).

    The toast is literal:

    Pass `offload_layers = "auto"` to from_pretrained to keep the decoder layers
    the GPU cannot hold in host RAM …
    

    Training already exposes Block Swap / offload_layers (including "auto"). Output / Export does not. Export’s load_checkpoint loads via FastLanguageModel / FastModel.from_pretrained with load_in_4bit and multi-GPU device_map, but never passes offload_layers. So when the checkpoint (or its base) does not fit for a 4-bit merge/GGUF load, bitsandbytes refuses the CPU spill and export dies — even though the same box has plenty of system RAM (reporter: ~80 GB free) and a manual Python load with offload_layers="auto" succeeds.

    This is separate from earlier Gemma-4 train/run fixes (#7055, #13388) and from GGUF converter/mmproj issues. It’s specifically “export load cannot use the offload path Training already has.”

    Narrow PR

    Keep the base-model / full-finetune semantics unchanged; only plumb what Training already has into Export:

    1. Accept offload_layers on the Export load/start API (default "auto" for the low-VRAM path, or mirror Training’s Auto control on the Output tab).
    2. Pass it through ExportBackend.load_checkpoint → every from_pretrained call used for merge / GGUF.
    3. Optional UI: the same Auto offload control Training shows, on Output, so users are not told to set something that isn’t there.

    Reporter already proved the library path works with offload_layers="auto"; Studio just never offers it on export.

    cc @danielhanchen

  7. danielhanchen commented on Oct 14, 2026

    @danielhanchen
    Member

    Fixed! The Output tab's export load never used the layer offloading Training already has, so on an 8 GB card the 4-bit Gemma 4 E2B load spilled to the CPU and bitsandbytes refused it. Export now retries that load automatically with the layers the GPU cannot hold kept in system RAM, so no new setting is needed. Fixed in #13720.
    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugfeature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions