| ```CODE: | |
| import torch | |
| from diffusers import DiffusionPipeline | |
| # switch to "mps" for apple devices | |
| pipe = DiffusionPipeline.from_pretrained("Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda") | |
| prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" | |
| image = pipe(prompt).images[0] | |
| ``` | |
| ERROR: | |
| Traceback (most recent call last): | |
| File "/tmp/Qwen_Qwen-Image_0uZLqPT.py", line 27, in <module> | |
| pipe = DiffusionPipeline.from_pretrained("Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda") | |
| File "/tmp/.cache/uv/environments-v2/29dc976ff856b6da/lib/python3.13/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn | |
| return fn(*args, **kwargs) | |
| File "/tmp/.cache/uv/environments-v2/29dc976ff856b6da/lib/python3.13/site-packages/diffusers/pipelines/pipeline_utils.py", line 1025, in from_pretrained | |
| loaded_sub_model = load_sub_model( | |
| library_name=library_name, | |
| ...<21 lines>... | |
| quantization_config=quantization_config, | |
| ) | |
| File "/tmp/.cache/uv/environments-v2/29dc976ff856b6da/lib/python3.13/site-packages/diffusers/pipelines/pipeline_loading_utils.py", line 860, in load_sub_model | |
| loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs) | |
| File "/tmp/.cache/uv/environments-v2/29dc976ff856b6da/lib/python3.13/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn | |
| return fn(*args, **kwargs) | |
| File "/tmp/.cache/uv/environments-v2/29dc976ff856b6da/lib/python3.13/site-packages/diffusers/models/modeling_utils.py", line 1288, in from_pretrained | |
| ) = cls._load_pretrained_model( | |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^ | |
| model, | |
| ^^^^^^ | |
| ...<13 lines>... | |
| is_parallel_loading_enabled=is_parallel_loading_enabled, | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| ) | |
| ^ | |
| File "/tmp/.cache/uv/environments-v2/29dc976ff856b6da/lib/python3.13/site-packages/diffusers/models/modeling_utils.py", line 1537, in _load_pretrained_model | |
| _caching_allocator_warmup(model, expanded_device_map, dtype, hf_quantizer) | |
| ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| File "/tmp/.cache/uv/environments-v2/29dc976ff856b6da/lib/python3.13/site-packages/diffusers/models/model_loading_utils.py", line 754, in _caching_allocator_warmup | |
| _ = torch.empty(warmup_elems, dtype=dtype, device=device, requires_grad=False) | |
| torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 38.05 GiB. GPU 0 has a total capacity of 22.03 GiB of which 21.84 GiB is free. Including non-PyTorch memory, this process has 186.00 MiB memory in use. Of the allocated memory 0 bytes is allocated by PyTorch, and 0 bytes is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables) | |