Repository navigation
Description
Environment
Where are you using Unsloth?
- Unsloth desktop application
- Unsloth web UI (
unsloth studio) - Unsloth CLI
- Python package or notebook
- Colab or Kaggle
Operating system and version:
Ubuntu 25.04 (kernel 6.14), Python 3.12.9.
GPU model(s) and accelerator backend:
AMD Radeon RX 9060 XT 16 GB, gfx1200 (RDNA4), backend ROCm 7.2.0
(/opt/rocm-7.2.0). The machine also has an iGPU (gfx1036); it is hidden with
HIP_VISIBLE_DEVICES=0 (with both visible, is_bfloat16_supported() returns
False).
Versions:
unsloth 2026.11.6 (git+https://github.com/unslothai/unsloth @ daf25ce),
unsloth_zoo 2026.11.6, torch 2.10.0+rocm7.0 (wheel
--index-url https://download.pytorch.org/whl/rocm7.0, the newest published
there), triton 3.6.0, transformers 5.12.1, trl 1.15.0, peft 0.21.3,
accelerate 1.16.0, datasets 4.8.5, bitsandbytes 0.50.2 (PyPI multi-backend;
AdamW8bit step and Linear4bit forward both run on gfx1200).
What happened?
QLoRA training of unsloth/Qwen3-8B-bnb-4bit aborts with HIP error: an illegal memory access was encountered (Error code 700) inside three different Unsloth
kernels, and evaluation aborts inside the decode graphs. Only one combination
ever finishes a full epoch, and it still aborts afterwards.
Steps to reproduce:
- Install the versions above (ROCm wheels for torch, PyPI bitsandbytes).
- Run QLoRA with r=16, alpha=32, dropout 0.1,
max_seq_length=8192,
per_device_train_batch_size=1,gradient_accumulation_steps=4,
optim="adamw_8bit", linear scheduler,packing=False,
train_on_responses_only(ChatML), fp16, standard HF gradient
checkpointing (a plainTrue, not"unsloth"). - Watch the step counter.
from unsloth import FastLanguageModel
from trl import SFTTrainer, SFTConfig
from unsloth.chat_templates import train_on_responses_only
from datasets import Dataset
model, tok = FastLanguageModel.from_pretrained(
"unsloth/Qwen3-8B-bnb-4bit", max_seq_length=8192, load_in_4bit=True,
dtype=__import__("torch").float16)
model = FastLanguageModel.get_peft_model(
model, r=16, lora_alpha=32, lora_dropout=0.1,
target_modules=["q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj"],
use_gradient_checkpointing=True, random_state=3407)
# ~4096-token ChatML rows; the prompt alone is ~1.8k tokens, so short windows
# mask every label ("train_on_responses_only masked all labels").
texts = ["<|im_start|>system\n...<|im_start|>user\n...<|im_start|>assistant\n{...}<|im_end|>"] * 95
trainer = SFTTrainer(model=model, processing_class=tok,
train_dataset=Dataset.from_dict({"text": texts}),
args=SFTConfig(dataset_text_field="text", max_length=8192,
packing=False, per_device_train_batch_size=1,
gradient_accumulation_steps=4,
num_train_epochs=3, learning_rate=2e-4,
fp16=True, bf16=False, optim="adamw_8bit",
lr_scheduler_type="linear", report_to="none",
output_dir="out"))
trainer = train_on_responses_only(trainer,
instruction_part="<|im_start|>user\n", response_part="<|im_start|>assistant\n")
trainer.train()Expected behavior:
The run completes its epochs (24 steps per epoch with 95 rows) and saves the
adapter.
Actual behavior:
Four reproducible failures, all reported asynchronously as HIP error: an illegal memory access (Error code 700):
| # | Configuration | Failure |
|---|---|---|
| 1 | use_gradient_checkpointing="unsloth" (your default/docs) |
aborts on step 1; one run completed the step but logged loss: nan. Standard HF checkpointing (True) fixes this |
| 2 | standard checkpointing + bf16 | aborts at ~step 10 in unsloth/kernels/swiglu.py::swiglu_fg_kernel (fast_lora.py::apply_lora_mlp_swiglu) |
| 3 | standard checkpointing + fp16, 8192 or 12288 | trains 21–24 steps, then aborts in unsloth_zoo/fused_losses/fused_linear.py (_ce_op → _ce_checked → _ce_impl → _keep_index). One run finished the full 24-step epoch (799.6 s, train_loss 0.551) and aborted at the epilogue: torch/utils/checkpoint.py → torch/random.py::fork_rng → cuda/random.py::set_rng_state |
| 4 | evaluation (model.generate) |
aborts in unsloth/models/_decode_graphs.py::generate_with_fallback, also with UNSLOTH_DISABLE_STATIC_GENERATION=1 |
Also tried, without success:
UNSLOTH_FUSED_LINEAR=0 (still aborts in fused_losses/fused_linear.py, ~step 21),
UNSLOTH_COMPILE_DISABLE=1 (aborts in compute_loss on step 1),
UNSLOTH_RETURN_LOGITS=1 (OOM: the 12288×151936 logits are converted to fp32,
3.87 GiB, with 2.90 GiB free), HIP_LAUNCH_BLOCKING=1 (survives one step; the
error is async and simply deferred), PYTORCH_ALLOC_CONF=expandable_segments:True.
Model and operation involved:
Model unsloth/Qwen3-8B-bnb-4bit; operation: training (QLoRA 4-bit) and
then inference for evaluation.
Diagnostics and logs
Python package tracebacks (trimmed to the last frames):
# failure 2 (bf16)
File ".../unsloth/kernels/fast_lora.py", line 844, in apply_lora_mlp_swiglu
File ".../unsloth/kernels/swiglu.py", line 56, in swiglu_fg_kernel
h = torch.empty((batch, seq_len, hd), dtype = e.dtype, device = e.device)
torch.AcceleratorError: HIP error: an illegal memory access was encountered
# failure 3 (fp16, fused CE)
File ".../unsloth_zoo/fused_losses/fused_linear.py", line 1856, in _ce_op
File ".../unsloth_zoo/fused_losses/fused_linear.py", line 2032, in _ce_checked
File ".../unsloth_zoo/fused_losses/fused_linear.py", line 1442, in wrapper
File ".../unsloth_zoo/fused_losses/fused_linear.py", line 1460, in _ce_impl
File ".../unsloth_zoo/fused_losses/fused_linear.py", line 1400, in _keep_index
terminate called after throwing an instance of 'c10::AcceleratorError'
what(): HIP error: an illegal memory access was encountered
# failure 4 (decode graphs)
File ".../unsloth/models/llama.py", line 3241, in unsloth_fast_generate
File ".../unsloth/models/_decode_graphs.py", line 459, in generate_with_fallback
File ".../transformers/generation/utils.py", line 2610, in _has_unfinished_sequences
torch.AcceleratorError: HIP error: an illegal memory access was encountered
Environment output that may matter:
Unsloth 2026.11.6: Fast Qwen3 patching. Transformers: 5.12.1.
AMD Radeon RX 9060 XT. Num GPUs = 1. Max memory: 15.922 GB. Platform: Linux.
Torch: 2.10.0+rocm7.0. ROCm Toolkit: 7.0.51831. Triton: 3.6.0
Bfloat16 = TRUE. FA [Xformers = None. FA2 = False]
[W...] Warning: Attempting to use CK on an unsupported architecture!
Cannot set backend to CK (function operator())
Skipping import of cpp extensions due to incompatible torch version.
Please upgrade to torch >= 2.11.0 (found 2.10.0+rocm7.0). # torchao
Additional context
The other half of the problem: plain PyTorch has no fused SDPA kernel for
gfx1200, so we cannot simply disable Unsloth's fused kernels and train with
vanilla HF — the math backend materialises the attention matrix and OOMs:
torch.backends.cuda.flash_sdp_enabled() # True
torch.nn.functional.scaled_dot_product_attention(q, q, q) under
torch.nn.attention.sdpa_kernel(SDPBackend.FLASH_ATTENTION)
# RuntimeError: No available kernel. Aborting execution.Plain transformers + bitsandbytes + peft QLoRA therefore fails with the
same OOM figures at 8192, 10240 and 12288 (12.79 GiB allocated, ~450 MiB free),
and a single 4096-token forward already exhausts the card. Unsloth's attention
is the only one that fits on this arch.
Questions
- Is
gfx1200+ torch 2.10 + ROCm 7.2 a combination you support today? The
ROCm work in ROCm: use flash varlen for packed rows so hybrid packing is faster than padding #18313 mentions torch 2.11 with ROCm 7.13/7.14 and gfx1151; if
gfx1200 needs that stack, we will move. - Should
swiglu_fg_kernel, the fused linear CE and the decode graphs be
gated off per arch on RDNA4, the wayarch_lacks_bf16()already gates gfx10?
Per-kernel kill-switches (CE, SwiGLU, decode graphs) would let us train with
the standard loss and still use Unsloth's attention. - If they are expected to work, what do you want from this machine:
AMD_SERIALIZE_KERNEL=3,TORCH_USE_HIP_DSA=1device-side assertions,
HIP_LAUNCH_BLOCKING=1output, or a repro? Related reports you may want to
link: ROCm: use flash varlen for packed rows so hybrid packing is faster than padding #18313 (ROCm varlen/flash, gfx1151 illegal memory access),
Unsloth Studio (AMD): leave an iGPU out of the Train page VRAM total and the default GPU pick (blocks dual R9700 testing) #14039 (gfx1200/gfx1201 + gfx1036 iGPU), [Feature] AMD: install PyTorch built for ROCm 7.14 or 10, not only ROCm 7.2, and let users pick #9932 (ROCm/torch version choice).
Activity
LeoBorcherding commentedon Nov 19, 2026
Same crash here on a second RX 9060 XT (gfx1200), Linux Mint 22.1, kernel 7.0, torch 2.11.0+rocm7.14.0 (repo.amd.com multi-arch wheels), bitsandbytes 0.50.2, transformers 5.5.0, trl 0.23.1, peft 0.18.1. Llama-3.1-8B 4-bit QLoRA, batch 2 x grad accum 4, max length 2048, no packing.
It's a regression: unsloth 2026.9.7 + zoo 2026.9.6 trains all 25 steps on the same box and the same packages (6.25 s/step, 7.4 GB). 2026.11.4 and 2026.11.6 both fail on the first step.
With
AMD_SERIALIZE_KERNEL=3the first failure ishipErrorInvalidValuefromF.scaled_dot_product_attentionin_sdpa_packed_segments. SettingUNSLOTH_SDPA_PACKED_SEGMENTS=0,UNSLOTH_DISABLE_AUTO_PADDING_FREE=1orTORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=0only moves the error elsewhere (a hipBLASLt GEMM memory fault, thenmatmul_lora), so it looks like an earlier kernel is corrupting memory. The same release trains fine on an R9700 (gfx1201) under Windows.LeoBorcherding commentedon Nov 19, 2026
Bisected on the RX 9060 XT (gfx1200, Linux, torch 2.11.0+rocm7.14.0): Llama-3.1-8B 4-bit QLoRA, 3 steps per commit. Two commits break it, both in the attention dispatch.
5babb22c69, first in 2026.10.1). Its parent9bf3dec615trains,5babb22c69fails at the first step withCUDA error: invalid argument.UNSLOTH_SDPA_PACKED_SEGMENTS=0makes5babb22c69, 2026.10.1 and 2026.10.4 train again.e6c95c292b, first in 2026.10.7). WithUNSLOTH_SDPA_PACKED_SEGMENTS=0set, its parentcefb057a4etrains ande6c95c292bfails the same way. From there on no env var gets training back: 2026.11.6 still fails with flash SDPA disabled, and withTORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=0it aborts with the illegal memory access from the original report.Both change which SDPA call GQA attention takes on ROCm (per-segment views with K/V expanded in #12740, expand vs
enable_gqapicked by_fused_sdp_choicein #14158), and #14158 lists ROCm as not run. I haven't isolated which kernel faults. unsloth_zoo isn't involved: unsloth 2026.10.1 with zoo 2026.9.9 fails, unsloth 2026.9.14 with zoo 2026.10.1 trains.ROCm attention: keep AOTriton SDPA kernels that fail a per-GPU self-c…
danielhanchen commentedon Nov 21, 2026
Thanks for the bisect, it pointed straight at the cause.
Unsloth turns on torch's experimental AOTriton attention kernels for ROCm on import (
TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=1). Up to 2026.9.7, GQA training on ROCm never actually reached them: packed and padding-free rows used a dense mask withenable_gqa, and only the math kernel takes that. #12740 moved packed rows to per-segment causal calls, which run on AOTriton flash. #14158 then expanded K/V for masked calls, which run on AOTriton memory-efficient. On gfx1200 those kernels fail (hipErrorInvalidValue) or corrupt memory, and the corruption surfaces later as an illegal memory access in SwiGLU, CE,fork_rngor decode.The fix is merged in #18453 and is in 2026.11.9 on PyPI. On each RDNA GPU, Unsloth runs a one-time check in a separate process that sends the shapes it uses through flash and memory-efficient, forward and backward, and compares them to an fp32 reference. A kernel that fails is kept out of Unsloth's attention on that GPU, and attention falls back to the math kernel there, as in 2026.9.7. CDNA and NVIDIA are unchanged. We could only test on gfx1151, where the kernels pass: there, training is unchanged, and forcing the check to fail moves every call to math with the same outputs. We have no gfx1200 here.
Could you upgrade (
pip install --upgrade --no-deps unsloth unsloth_zoo) and run your repro on the RX 9060 XT and post:Unsloth: ROCm gfx1200 0: AOTriton, if it prints.from unsloth.utils.attention_dispatch import rocm_sdpa_verdict; print(rocm_sdpa_verdict(0))after loading the model.If you have to stay on 2026.11.6, the closest workaround is
TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=0, which keeps every SDPA call on math. You reported that 2026.11.6 still faulted for you with it set. If it still faults after the fix, the verdict output will tell us whether a kernel outside attention is involved.