Repository navigation
Description
Hello!
Qwen3-30B-A3B not loading on RTX4090
model, tokenizer = FastModel.from_pretrained( #unsloth/Qwen2.5-Coder-32B-Instruct
model_name = "unsloth/Qwen3-30B-A3B", # "unsloth/Mistral-Nemo-Base-2407",
max_seq_length = max_seq_length,
load_in_4bit = True,
#full_finetuning = True, # We have full finetuning now!
load_in_8bit = False, # [NEW!] A bit more accurate, uses 2x memory
full_finetuning = False,
#local_files_only = True,
# token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
)
🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.
🦥 Unsloth Zoo will now patch everything to make training faster!
==((====))== Unsloth 2025.4.8: Fast Qwen3 patching. Transformers: 4.51.3.
\ /| NVIDIA GeForce RTX 4090. Num GPUs = 1. Max memory: 23.988 GB. Platform: Linux.
O^O/ _/ \ Torch: 2.7.0+cu128. CUDA: 8.9. CUDA Toolkit: 12.8. Triton: 3.3.0
\ / Bfloat16 = TRUE. FA [Xformers = 0.0.30. FA2 = False]
"-____-" Free license: http://github.com/unslothai/unsloth
Unsloth: Fast downloading is enabled - ignore downloading bars which are red colored!
Loading widget...
RuntimeError Traceback (most recent call last)
Cell In[2], line 26
10 # 4bit pre quantized models we support for 4x faster downloading + no OOMs.
11 fourbit_models = [
12 "unsloth/Meta-Llama-3.1-8B-bnb-4bit", # Llama-3.1 15 trillion tokens model 2x faster!
13 "unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit",
(...)
23 "unsloth/gemma-2-27b-bnb-4bit", # Gemma 2x faster!
24 ] # More models at https://huggingface.co/unsloth
---> 26 model, tokenizer = FastModel.from_pretrained( #unsloth/Qwen2.5-Coder-32B-Instruct
27 model_name = "unsloth/Qwen3-30B-A3B", # "unsloth/Mistral-Nemo-Base-2407",
28 max_seq_length = max_seq_length,
29 load_in_4bit = True,
30 #full_finetuning = True, # We have full finetuning now!
31 load_in_8bit = False, # [NEW!] A bit more accurate, uses 2x memory
32 full_finetuning = False,
33
34 #local_files_only = True,
35 # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
36 )
File ~/anaconda3/envs/unsloth/lib/python3.11/site-packages/unsloth/models/loader.py:732, in FastModel.from_pretrained(model_name, max_seq_length, dtype, load_in_4bit, load_in_8bit, full_finetuning, token, device_map, rope_scaling, fix_tokenizer, trust_remote_code, use_gradient_checkpointing, resize_model_vocab, revision, return_logits, fullgraph, use_exact_model_name, auto_model, whisper_language, whisper_task, *args, **kwargs)
729 if auto_model is None:
730 auto_model = AutoModelForVision2Seq if is_vlm else AutoModelForCausalLM
--> 732 model, tokenizer = FastBaseModel.from_pretrained(
733 model_name = model_name,
734 max_seq_length = max_seq_length,
735 dtype = _get_dtype(dtype),
736 load_in_4bit = load_in_4bit,
737 load_in_8bit = load_in_8bit,
738 full_finetuning = full_finetuning,
739 token = token,
740 device_map = device_map,
741 trust_remote_code = trust_remote_code,
742 revision = revision if not is_peft else None,
743 model_types = model_types,
744 tokenizer_name = tokenizer_name,
745 auto_model = auto_model,
746 use_gradient_checkpointing = use_gradient_checkpointing,
747 supports_sdpa = supports_sdpa,
748 whisper_language = whisper_language,
749 whisper_task = whisper_task,
750 *args, **kwargs,
751 )
753 if resize_model_vocab is not None:
754 model.resize_token_embeddings(resize_model_vocab)
File ~/anaconda3/envs/unsloth/lib/python3.11/site-packages/unsloth/models/vision.py:359, in FastBaseModel.from_pretrained(model_name, max_seq_length, dtype, load_in_4bit, load_in_8bit, full_finetuning, token, device_map, trust_remote_code, model_types, tokenizer_name, auto_model, use_gradient_checkpointing, supports_sdpa, whisper_language, whisper_task, **kwargs)
356 torch_dtype = dtype
357 if do_forced_float32: torch_dtype = torch.bfloat16
--> 359 model = auto_model.from_pretrained(
360 model_name,
361 device_map = device_map,
362 torch_dtype = torch_dtype,
363 # quantization_config = bnb_config,
364 token = token,
365 trust_remote_code = trust_remote_code,
366 # attn_implementation = attn_implementation,
367 **kwargs,
368 )
369 # Return old flag
370 os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = old_hf_transfer
File ~/anaconda3/envs/unsloth/lib/python3.11/site-packages/transformers/models/auto/auto_factory.py:571, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
569 if model_class.config_class == config.sub_configs.get("text_config", None):
570 config = config.get_text_config()
--> 571 return model_class.from_pretrained(
572 pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs
573 )
574 raise ValueError(
575 f"Unrecognized configuration class {config.class} for this kind of AutoModel: {cls.name}.\n"
576 f"Model type should be one of {', '.join(c.name for c in cls._model_mapping.keys())}."
577 )
File ~/anaconda3/envs/unsloth/lib/python3.11/site-packages/transformers/modeling_utils.py:279, in restore_default_torch_dtype.._wrapper(*args, **kwargs)
277 old_dtype = torch.get_default_dtype()
278 try:
--> 279 return func(*args, **kwargs)
280 finally:
281 torch.set_default_dtype(old_dtype)
File ~/anaconda3/envs/unsloth/lib/python3.11/site-packages/transformers/modeling_utils.py:4399, in PreTrainedModel.from_pretrained(cls, pretrained_model_name_or_path, config, cache_dir, ignore_mismatched_sizes, force_download, local_files_only, token, revision, use_safetensors, weights_only, *model_args, **kwargs)
4389 if dtype_orig is not None:
4390 torch.set_default_dtype(dtype_orig)
4392 (
4393 model,
4394 missing_keys,
4395 unexpected_keys,
4396 mismatched_keys,
4397 offload_index,
4398 error_msgs,
-> 4399 ) = cls._load_pretrained_model(
4400 model,
4401 state_dict,
4402 checkpoint_files,
4403 pretrained_model_name_or_path,
4404 ignore_mismatched_sizes=ignore_mismatched_sizes,
4405 sharded_metadata=sharded_metadata,
4406 device_map=device_map,
4407 disk_offload_folder=offload_folder,
4408 offload_state_dict=offload_state_dict,
4409 dtype=torch_dtype,
4410 hf_quantizer=hf_quantizer,
4411 keep_in_fp32_regex=keep_in_fp32_regex,
4412 device_mesh=device_mesh,
4413 key_mapping=key_mapping,
4414 weights_only=weights_only,
4415 )
4417 # make sure token embedding weights are still tied if needed
4418 model.tie_weights()
File ~/anaconda3/envs/unsloth/lib/python3.11/site-packages/transformers/modeling_utils.py:4833, in PreTrainedModel._load_pretrained_model(cls, model, state_dict, checkpoint_files, pretrained_model_name_or_path, ignore_mismatched_sizes, sharded_metadata, device_map, disk_offload_folder, offload_state_dict, dtype, hf_quantizer, keep_in_fp32_regex, device_mesh, key_mapping, weights_only)
4831 # Skip it with fsdp on ranks other than 0
4832 elif not (is_fsdp_enabled() and not is_local_dist_rank_0() and not is_quantized):
-> 4833 disk_offload_index, cpu_offload_index = _load_state_dict_into_meta_model(
4834 model_to_load,
4835 state_dict,
4836 shard_file,
4837 expected_keys,
4838 reverse_key_renaming_mapping,
4839 device_map=device_map,
4840 disk_offload_folder=disk_offload_folder,
4841 disk_offload_index=disk_offload_index,
4842 cpu_offload_folder=cpu_offload_folder,
4843 cpu_offload_index=cpu_offload_index,
4844 hf_quantizer=hf_quantizer,
4845 is_safetensors=is_offloaded_safetensors,
4846 keep_in_fp32_regex=keep_in_fp32_regex,
4847 unexpected_keys=unexpected_keys,
4848 device_mesh=device_mesh,
4849 )
4851 # force memory release if loading multiple shards, to avoid having 2 state dicts in memory in next loop
4852 del state_dict
File ~/anaconda3/envs/unsloth/lib/python3.11/site-packages/torch/utils/_contextlib.py:116, in context_decorator..decorate_context(*args, **kwargs)
113 @functools.wraps(func)
114 def decorate_context(*args, **kwargs):
115 with ctx_factory():
--> 116 return func(*args, **kwargs)
File ~/anaconda3/envs/unsloth/lib/python3.11/site-packages/transformers/modeling_utils.py:827, in _load_state_dict_into_meta_model(model, state_dict, shard_file, expected_keys, reverse_renaming_mapping, device_map, disk_offload_folder, disk_offload_index, cpu_offload_folder, cpu_offload_index, hf_quantizer, is_safetensors, keep_in_fp32_regex, unexpected_keys, device_mesh)
824 _load_parameter_into_model(model, param_name, param.to(param_device))
826 else:
--> 827 hf_quantizer.create_quantized_param(
828 model, param, param_name, param_device, state_dict, unexpected_keys
829 )
830 # For quantized modules with FSDP/DeepSpeed Stage 3, we need to quantize the parameter on the GPU
831 # and then cast it to CPU to avoid excessive memory usage on each GPU
832 # in comparison to the sharded model across GPUs.
833 if is_fsdp_enabled() or is_deepspeed_zero3_enabled():
File ~/anaconda3/envs/unsloth/lib/python3.11/site-packages/transformers/quantizers/quantizer_bnb_4bit.py:243, in Bnb4BitHfQuantizer.create_quantized_param(self, model, param_value, param_name, target_device, state_dict, unexpected_keys)
240 new_value = new_value.T
242 kwargs = old_value.dict
--> 243 new_value = bnb.nn.Params4bit(new_value, requires_grad=False, **kwargs).to(target_device)
245 module._parameters[tensor_name] = new_value
File ~/anaconda3/envs/unsloth/lib/python3.11/site-packages/bitsandbytes/nn/modules.py:331, in Params4bit.to(self, *args, **kwargs)
328 device, dtype, non_blocking, convert_to_format = torch._C._nn._parse_to(*args, **kwargs)
330 if device is not None and device.type == "cuda" and not self.bnb_quantized:
--> 331 return self._quantize(device)
332 else:
333 if self.quant_state is not None:
File ~/anaconda3/envs/unsloth/lib/python3.11/site-packages/bitsandbytes/nn/modules.py:296, in Params4bit._quantize(self, device)
294 def _quantize(self, device):
295 w = self.data.contiguous().to(device)
--> 296 w_4bit, quant_state = bnb.functional.quantize_4bit(
297 w,
298 blocksize=self.blocksize,
299 compress_statistics=self.compress_statistics,
300 quant_type=self.quant_type,
301 quant_storage=self.quant_storage,
302 )
303 self.data = w_4bit
304 self.quant_state = quant_state
File ~/anaconda3/envs/unsloth/lib/python3.11/site-packages/bitsandbytes/functional.py:1212, in quantize_4bit(A, absmax, out, blocksize, compress_statistics, quant_type, quant_storage)
1210 if out is None:
1211 mod = dtype2bytes[quant_storage] * 2
-> 1212 out = torch.zeros(((n + 1) // mod, 1), dtype=quant_storage, device=A.device)
1214 assert blocksize in [4096, 2048, 1024, 512, 256, 128, 64]
1216 is_on_gpu([A, out, absmax])
RuntimeError: CUDA driver error: out of memory
Activity
rolandtannous commentedon May 9, 2025
@Romiroz
The unsloth/Qwen3-30B-A3B requires 29.6GB VRAM to load while your card only has 24GB of VRAM that is why you are running out of memory
Use a smaller model.
Romiroz commentedon May 9, 2025
In pinned message I see what this model needs 17.5 Gb and try to load. Now I read thread and see what we must ge latest unsloth from github. Thank you!
rolandtannous commentedon May 9, 2025
@Romiroz i just relabeled this thread and will keep it open. You are not wrong.
Indeed I just tested in a new fresh environment with unsloth-zoo and unsloth installed directly from github repo.
This code
Removing
use_gradient_checkpointingresults in the same memory consumption pattern explained below.The model consumes up to 43GB VRAM while the shards are being loaded (takes around a minute).
After the shards are completely loaded, the VRAM usage goes down to 16.8GB VRAM
worth investigating.
[-][Bug][/-][+][Bug] Not enough memory for Qwen3-30B-A3B on RTX4090 24 Gb[/+]Romiroz commentedon May 9, 2025
if i use use_gradient_checkpointing = "unsloth" on latest version from github, then i have folowing error:
ValueError: Some modules are dispatched on the CPU or the disk. Make sure you have enough GPU RAM to fit the quantized model. If you want to dispatch the model on the CPU or the disk while keeping these modules in 32-bit, you need to set
llm_int8_enable_fp32_cpu_offload=Trueand pass a customdevice_maptofrom_pretrained. Check https://huggingface.co/docs/transformers/main/en/main_classes/quantization#offload-between-cpu-and-gpu for more details.rolandtannous commentedon May 9, 2025
Setting use_gradient_checkpointing to True, still results in the same very high memory consumption pattern that I showcased, meaning the model is taking up to 40GB of GPU VRAM when shards are being loaded. Your card only has 24GB VRAM, so in this case it's trying to offload some of the layers or modules to disk or CPU. This is not a solution though and will probably be super slow. Someone is looking into this.
icsy7867 commentedon May 11, 2025
Experiencing the same.
Romiroz commentedon May 11, 2025
If someone have a time, try to install Pytorch 2.7 with CUDA Toolkit 12.8. it looks like everything works faster with version 12.8. Training time with another QWEN-3 is less.
icsy7867 commentedon May 12, 2025
So this is odd...
When using unsloth 2025.4.7, I get past this error and the shards start to load. Though I get an error about invalid syntax:
BUT, when I uprade my environment to the latest version 2025.5.1 I immediately get the error described in this post.
@Romiroz Did you get past the error you mentioned above?
Romiroz commentedon May 13, 2025
I think this thread become duplicate to pinned main thread. We are waiting for fixes. May be this error beacause you using FastLanguageModel instead of FastModel ?
github-actions commentedon Jul 1, 2025
Is this issue still important to you? Apologies in advance we might have missed this issue as well. For faster response times, please post on our Reddit server - https://www.reddit.com/r/unsloth or our Discord - https://discord.com/invite/unsloth
matthusby commentedon Jul 28, 2025
Does anyone know if there has been updates for this? I was just trying on a 3090 and ran into the same OOM problem.
fullstackwebdev commentedon Aug 7, 2025
hey when I ran this in April it loaded qwen3-30b-a3b on my 3090. But today I get the same error as above.
I tried installing from git and reinstalling unsloth-zoo.
smoke.py:
mmathew23 commentedon Sep 10, 2025
Hi @fullstackwebdev could you provide the full training setup? I don't need details about the dataset, but the peft model and Trainer details would be nice to have to help troubleshoot.
David-AU-github commentedon Sep 17, 2025
Wondering about this too ; same errors - > "...offload cpu/disk".
Set my GPU to be able to offload onto "reg" ram, when over the limit.
No issues this far, until "MOE" (training) time.
Win 11, Nvidia , 12.6 Cuda.
mmathew23 commentedon Sep 18, 2025
Hi @David-AU-github @fullstackwebdev @matthusby @icsy7867
This should actually now be fixed in the latest version of unsloth.
pip install --no-deps --upgrade --force-reinstall unsloth unsloth_zooTry the following