Skip to content

[Bug] Getting error "indices should be either on cpu or on the same device as the indexed tensor (cuda:0)" when trying to train Gemma 4 31b since upgrading to v0.1.806-beta #11952

Closed

Description

@MikeStone66

name: Unsloth Studio Bug
about: Report a problem with the Unsloth Studio desktop app or web UI
title: "[Unsloth Bug] "
labels: bug
assignees: ""

Environment

Where are you using Unsloth?

Unsloth desktop application

Operating system and version:
Windows 11

GPU model(s) and accelerator backend:

4 x RTX 4060Ti 16gb CUDA
Versions:
v0.1.814-beta
Package Version
2026.9.10
llama.cpp Version
b11160-mix-a6922cc

What happened?

I had been working on a CPT>SFT>DPO project with Gemma 4 31b for a couple of weeks and it been going smooth until I upgraded to v0.1.806-beta last week then i immediately started getting the above error. I tried rolling back but it didnt help. I can still train Gemma 4 12b, Nemo 12b, Mistral small 24 normally but gemma4 31b errors before first step

Steps to reproduce:

1.Start unsloth
2.choose Gemma 4 31b and start training run

Expected behavior:
Training runs as normal
Actual behavior:
Get error "indices should be either on cpu or on the same device as the indexed tensor (cuda:0)"

UnslothTraceback.txt

Model and operation involved:

Diagnostics and logs

Desktop application

Click Copy Diagnostics on the error, startup, or update screen and paste the
result below:

==((====))==  Unsloth - 2x faster free finetuning | Num GPUs used = 2
   \\   /|    Num examples = 10,282 | Num Epochs = 2 | Total steps = 644
O^O/ \_/ \    Batch size per device = 2 | Gradient accumulation steps = 16
\        /    Data Parallel GPUs = 1 | Total batch size (2 x 16 x 1) = 32
 "-____-"     Trainable parameters = 122,429,440 of 31,395,515,952 (0.39% trained)
Unsloth: Not an error, but Gemma4ForConditionalGeneration does not accept `num_items_in_batch`.
Using gradient accumulation will be very slightly less accurate.
Read more on gradient accumulation issues here: https://unsloth.ai/blog/gradient
{"timestamp": "2026-09-25T16:51:16.353966Z", "level": "info", "event": "request_completed", "method": "GET", "path": "/api/train/runs", "status_code": 200, "process_time_ms": 1343.38}
{"timestamp": "2026-09-25T16:51:16.897766Z", "level": "info", "event": "request_completed", "method": "GET", "path": "/api/inference/monitor", "status_code": 200, "process_time_ms": 3.76}
{"timestamp": "2026-09-25T16:51:26.955645Z", "level": "info", "event": "request_completed", "method": "GET", "path": "/api/inference/monitor", "status_code": 200, "process_time_ms": 4.02}
{"timestamp": "2026-09-25T16:51:31.314679Z", "level": "info", "event": "request_completed", "method": "GET", "path": "/api/train/runs", "status_code": 200, "process_time_ms": 1302.4}
{"timestamp": "2026-09-25T16:51:31.825676Z", "level": "error", "event": "Training error: indices should be either on cpu or on the same device as the indexed tensor (cuda:0)"}
{"timestamp": "2026-09-25T16:51:31.831675Z", "level": "error", "event": "Full traceback:\nTraceback (most recent call last):\n  File \"C:\\Users\\mikee\\.unsloth\\studio\\unsloth_studio\\Lib\\site-packages\\studio\\backend\\core\\training\\trainer.py\", line 4537, in _train_worker\n    self.trainer.train(\n  File \"C:\\Users\\mikee\\.unsloth\\studio\\unsloth_studio\\Lib\\site-packages\\unsloth\\trainer.py\", line 1549, in _train_with_reset\n    return _orig_train(*train_args, **train_kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\mikee\\.unsloth\\studio\\compiled_cache\\UnslothSFTTrainer.py\", line 116, in wrapper\n    output = f(self, *args, **kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\mikee\\.unsloth\\studio\\.venv_t5_550\\transformers\\trainer.py\", line 1424, in train\n    return inner_training_loop(\n           ^^^^^^^^^^^^^^^^^^^^\n  File \"<string>\", line 81, in _fast_inner_training_loop\n  File \"C:\\Users\\mikee\\.unsloth\\studio\\.venv_t5_550\\transformers\\trainer.py\", line 1734, in _run_epoch\n    tr_loss_step = self.training_step(model, inputs, num_items_in_batch)\n                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\mikee\\.unsloth\\studio\\compiled_cache\\UnslothSFTTrainer.py\", line 1438, in training_step\n    return super().training_step(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\mikee\\.unsloth\\studio\\unsloth_studio\\Lib\\site-packages\\unsloth\\models\\_utils.py\", line 3838, in _unsloth_training_step_settling_fallbacks\n    return _training_step_before_settle(self, *args, **kwargs)\n           ^^^^^^^^^^^^^^\n... [21877 chars omitted; raise UNSLOTH_STUDIO_MAX_EXCEPTION_CHARS to see it all] ...\nile \"C:\\Users\\mikee\\.unsloth\\studio\\unsloth_studio\\Lib\\site-packages\\torch\\_dynamo\\_trace_wrapped_higher_order_op.py\", line 100, in forward\n    return torch.ops.aten.index(x, indices)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\mikee\\.unsloth\\studio\\unsloth_studio\\Lib\\site-packages\\torch\\_ops.py\", line 1269, in __call__\n    return self._op(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^\nRuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cuda:0)\n"}
{"timestamp": "2026-09-25T16:51:31.832676Z", "level": "error", "event": "Training error: indices should be either on cpu or on the same device as the indexed tensor (cuda:0)"}

If Copy Diagnostics is unavailable, attach the newest relevant files from:

  • Windows: %USERPROFILE%\.unsloth\studio\
  • Linux/macOS: ~/.unsloth/studio/

Useful files include:

  • tauri.log and, if relevant, tauri.log.1
  • logs/install-*.log, logs/update-*.log, logs/repair-*.log, or logs/backend-*.log
  • The newest logs/server/server-*.log

Unsloth web UI

Attach the newest relevant items:

  • Linux/macOS/Windows: ~/.unsloth/studio/logs/server/server-*.log
    (use %USERPROFILE%\.unsloth\studio\logs\server\ on Windows)
  • Linux/macOS shortcut launches only: ~/.local/share/unsloth/studio.log
  • Terminal output if Unsloth was launched from a terminal
  • Browser Console errors for browser-only problems

If you configured UNSLOTH_STUDIO_HOME or STUDIO_HOME, look under
<CUSTOM_STUDIO_HOME>/logs/ instead.

Model-specific logs, if applicable

  • GGUF/llama.cpp: newest ~/.unsloth/studio/logs/llama-server/*.log
  • Diffusion GGUF: newest ~/.unsloth/studio/logs/diffusion-server/*.log
  • Training resume/checkpoint bug: relevant trainer_state.json

Python package or notebook, if applicable

Paste the complete traceback and minimal reproduction:

# Remove all tokens and private data.

Also include Python, Unsloth, unsloth_zoo, PyTorch, Transformers, and TRL
versions, plus nvidia-smi output when applicable.

Additional context

Activity

  1. added
    feature request
    on Sep 25, 2026
  2. self-assigned this
    on Sep 28, 2026
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