Skip to content

AttributeError: 'StaticCache' object has no attribute 'dtype'. Did you mean: '_dtype'? #848

@azhuvath

Description

@azhuvath

Describe the bug

I am trying to quantize the model mistralai/Mistral-7B-Instruct-v0.3 following the documentation at https://github.com/intel/intel-extension-for-pytorch/tree/xpu-main/examples/gpu/llm/inference . I am getting this error while quantizing it.

Create an environment for IPEX

python3 -m venv ipex_env
source ipex_env/bin/activate
python -m pip install pip --upgrade
python -m pip install torch==2.7.0 torchvision==0.22.0 torchaudio==2.7.0 --index-url https://download.pytorch.org/whl/xpu
python -m pip install intel-extension-for-pytorch==2.7.10+xpu oneccl_bind_pt==2.7.0+xpu --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/
pip install transformers protobuf sentencepiece neural-compressor[pt] accelerate datasets numba einops diffusers

Output while quantizing the model

[W722 17:35:06.151652714 OperatorEntry.cpp:154] Warning: Warning only once for all operators, other operators may also be overridden.
Overriding a previously registered kernel for the same operator and the same dispatch key
operator: aten::geometric_(Tensor(a!) self, float p, *, Generator? generator=None) -> Tensor(a!)
registered at /pytorch/build/aten/src/ATen/RegisterSchema.cpp:6
dispatch key: XPU
previous kernel: registered at /pytorch/aten/src/ATen/VmapModeRegistrations.cpp:37
new kernel: registered at /build/intel-pytorch-extension/build/Release/csrc/gpu/csrc/gpu/xpu/ATen/RegisterXPU_0.cpp:186 (function operator())
2025-07-22 17:35:09 [WARNING][logger.py:139] Auto detect accelerator: XPU_Accelerator.
2025-07-22 17:35:11 [INFO][modeling_auto.py:138] Applying Weight Only Quantization.
2025-07-22 17:35:11 [INFO][utility.py:357] Processor type detected as Server due to the memory size is greater than 32GB.
Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:01<00:00, 2.91it/s]
2025-07-22 17:35:12 [INFO][utils.py:369] Set the environment variable INC_TARGET_DEVICE='cpu' to ensure the quantization process occurs on the CPU.
2025-07-22 17:35:12 [INFO][utils.py:390] Do RTN algorithm with config RTNConfig {
"local": {
".*lm_head": {
"dtype": "fp32",
"bits": 4,
"use_sym": true,
"group_size": 32,
"group_dim": 1,
"use_full_range": false,
"use_mse_search": false,
"use_layer_wise": false,
"model_path": "",
"use_double_quant": false,
"double_quant_bits": 8,
"double_quant_dtype": "int",
"double_quant_use_sym": false,
"double_quant_group_size": 256,
"quant_lm_head": false,
"_is_initialized": true
},
".*transformer.output_layer": {
"dtype": "fp32",
"bits": 4,
"use_sym": true,
"group_size": 32,
"group_dim": 1,
"use_full_range": false,
"use_mse_search": false,
"use_layer_wise": false,
"model_path": "",
"use_double_quant": false,
"double_quant_bits": 8,
"double_quant_dtype": "int",
"double_quant_use_sym": false,
"double_quant_group_size": 256,
"quant_lm_head": false,
"_is_initialized": true
},
".*embed_out": {
"dtype": "fp32",
"bits": 4,
"use_sym": true,
"group_size": 32,
"group_dim": 1,
"use_full_range": false,
"use_mse_search": false,
"use_layer_wise": false,
"model_path": "",
"use_double_quant": false,
"double_quant_bits": 8,
"double_quant_dtype": "int",
"double_quant_use_sym": false,
"double_quant_group_size": 256,
"quant_lm_head": false,
"_is_initialized": true
}
},
"global": {
"dtype": "int4",
"bits": 4,
"use_sym": true,
"group_size": 64,
"group_dim": 1,
"use_full_range": false,
"use_mse_search": false,
"use_layer_wise": false,
"model_path": "",
"use_double_quant": false,
"double_quant_bits": 8,
"double_quant_dtype": "int",
"double_quant_use_sym": false,
"double_quant_group_size": 256,
"quant_lm_head": false,
"_is_initialized": true
}
}

2025-07-22 17:35:12 [INFO][utils.py:391] Preparation started.
2025-07-22 17:35:12 [WARNING][logger.py:139] The configuration for .*lm_head has already been set, update it.
2025-07-22 17:35:12 [WARNING][logger.py:139] The configuration for .*embed_out has already been set, update it.
2025-07-22 17:35:12 [INFO][quantize.py:173] Start to prepare model with rtn.
2025-07-22 17:35:12 [INFO][utils.py:391] Preparation end.
2025-07-22 17:35:12 [INFO][utils.py:392] Conversion started.
2025-07-22 17:35:12 [WARNING][logger.py:139] The configuration for .*lm_head has already been set, update it.
2025-07-22 17:35:12 [WARNING][logger.py:139] The configuration for .*output_layer has already been set, update it.
2025-07-22 17:35:12 [WARNING][logger.py:139] The configuration for .*embed_out has already been set, update it.
2025-07-22 17:35:12 [INFO][quantize.py:242] Start to convert model with rtn.
2025-07-22 17:35:12 [WARNING][logger.py:139] Force use cpu accelerator.
2025-07-22 17:35:34 [INFO][utility.py:406] |Mixed Precision Statistics|
2025-07-22 17:35:34 [INFO][utility.py:408] +---------+-------+-----------+--------+
2025-07-22 17:35:34 [INFO][utility.py:408] | Op Type | Total | A32W4G64 | FP32 |
2025-07-22 17:35:34 [INFO][utility.py:408] +---------+-------+-----------+--------+
2025-07-22 17:35:34 [INFO][utility.py:408] | Linear | 225 | 224 | 1 |
2025-07-22 17:35:34 [INFO][utility.py:408] +---------+-------+-----------+--------+
2025-07-22 17:35:34 [INFO][utils.py:392] Conversion end.
2025-07-22 17:35:34 [WARNING][logger.py:139] The recommended ipex version is higher than 2.3.10 for xpu device.
2025-07-22 17:35:35 [INFO][modeling_auto.py:239] WeightOnlyQuant done.
2025-07-22 17:35:38 [INFO][quantization_config.py:224] Configuration saved in ./mistral7b_woq_int4/quantize_config.json
/home/sdp/fmt/ipex_env/lib/python3.12/site-packages/intel_extension_for_pytorch/transformers/optimize.py:2426: UserWarning: The transformers version is 4.53.3, bigger than validated 4.48.3, may have risks
warnings.warn(
xpu optimize_transformers function is activated
Warning: we didn't find deepspeed package in your environment, all deepspeed related feature will be disabled
tp size less than 2, tensor parallel will be disabled
The attention mask and the pad token id were not set. As a consequence, you may observe unexpected behavior. Please pass your input's attention_mask to obtain reliable results.
Setting pad_token_id to eos_token_id:2 for open-end generation.
The attention mask is not set and cannot be inferred from input because pad token is same as eos token. As a consequence, you may observe unexpected behavior. Please pass your input's attention_mask to obtain reliable results.
Traceback (most recent call last):
File "/home/sdp/fmt/quantize_mistral_model.py", line 65, in
generated_ids = model.generate(input_ids, max_new_tokens=512, cache_implementation="static")[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/sdp/fmt/ipex_env/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/sdp/fmt/ipex_env/lib/python3.12/site-packages/transformers/generation/utils.py", line 2625, in generate
result = self._sample(
^^^^^^^^^^^^^
File "/home/sdp/fmt/ipex_env/lib/python3.12/site-packages/transformers/generation/utils.py", line 3599, in _sample
model_inputs = self.prepare_inputs_for_generation(input_ids, **model_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/sdp/fmt/ipex_env/lib/python3.12/site-packages/intel_extension_for_pytorch/transformers/models/xpu/optimize_transformers/modules/Functions.py", line 238, in prepare_inputs_for_generation_ipex_wrapper
model_inputs["past_key_values"] = warp_cache_if_needed(
^^^^^^^^^^^^^^^^^^^^^
File "/home/sdp/fmt/ipex_env/lib/python3.12/site-packages/intel_extension_for_pytorch/transformers/models/xpu/optimize_transformers/modules/transformer_modules/CacheUtils.py", line 262, in warp_cache_if_needed
return IPEXStaticCache(cache, CacheFormat.FBNH)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/sdp/fmt/ipex_env/lib/python3.12/site-packages/intel_extension_for_pytorch/transformers/models/xpu/optimize_transformers/modules/transformer_modules/CacheUtils.py", line 30, in init
self.dtype = cache.dtype
^^^^^^^^^^^
AttributeError: 'StaticCache' object has no attribute 'dtype'. Did you mean: '_dtype'?

Versions

[W722 18:08:24.675335641 OperatorEntry.cpp:154] Warning: Warning only once for all operators, other operators may also be overridden.
Overriding a previously registered kernel for the same operator and the same dispatch key
operator: aten::geometric_(Tensor(a!) self, float p, *, Generator? generator=None) -> Tensor(a!)
registered at /pytorch/build/aten/src/ATen/RegisterSchema.cpp:6
dispatch key: XPU
previous kernel: registered at /pytorch/aten/src/ATen/VmapModeRegistrations.cpp:37
new kernel: registered at /build/intel-pytorch-extension/build/Release/csrc/gpu/csrc/gpu/xpu/ATen/RegisterXPU_0.cpp:186 (function operator())
Collecting environment information...

PyTorch version: 2.7.0+xpu
PyTorch CXX11 ABI: Yes
IPEX version: 2.7.10+xpu
IPEX commit: 0e47515
Build type: Release

OS: Ubuntu 24.04.2 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Clang version: N/A
IGC version: N/A
CMake version: N/A
Libc version: glibc-2.39

Python version: 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-6.14.0-24-generic-x86_64-with-glibc2.39
Is XPU available: True
DPCPP runtime: N/A
MKL version: N/A

GPU models and configuration onboard:
N/A

GPU models and configuration detected:

  • [0] _XpuDeviceProperties(name='Intel(R) Graphics [0xe211]', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', driver_version='1.6.33944+13', total_memory=23256MB, max_compute_units=160, gpu_eu_count=160, gpu_subslice_count=20, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)

Driver version:

  • intel_opencl: 25.22.33944.13-124.04ppa1
  • level_zero: N/A

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 46 bits physical, 48 bits virtual
Byte Order: Little Endian
CPU(s): 24
On-line CPU(s) list: 0-23
Vendor ID: GenuineIntel
Model name: Intel(R) Core(TM) Ultra 9 285
CPU family: 6
Model: 198
Thread(s) per core: 1
Core(s) per socket: 24
Socket(s): 1
Stepping: 2
CPU(s) scaling MHz: 50%
CPU max MHz: 5800.0000
CPU min MHz: 800.0000
BogoMIPS: 4992.00
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdt_a rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni lam wbnoinvd dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq rdpid bus_lock_detect movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 768 KiB (20 instances)
L1i cache: 1.3 MiB (20 instances)
L2 cache: 40 MiB (12 instances)
L3 cache: 36 MiB (1 instance)
NUMA node(s): 1
NUMA node0 CPU(s): 0-23
Vulnerability Gather data sampling: Not affected
Vulnerability Ghostwrite: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected

Versions of relevant libraries:
[pip] dpcpp-cpp-rt==2025.0.4
[pip] impi-devel==2021.14.1
[pip] impi-rt==2021.14.1
[pip] intel-cmplr-lib-rt==2025.0.4
[pip] intel-cmplr-lib-ur==2025.0.4
[pip] intel-cmplr-lic-rt==2025.0.4
[pip] intel_extension_for_pytorch==2.7.10+xpu
[pip] intel-opencl-rt==2025.0.4
[pip] intel-openmp==2025.0.4
[pip] intel-pti==0.10.1
[pip] intel-sycl-rt==2025.0.4
[pip] mkl==2025.0.1
[pip] mkl-dpcpp==2025.0.1
[pip] numpy==1.26.4
[pip] oneccl==2021.14.1
[pip] oneccl-bind-pt==2.7.0+xpu
[pip] oneccl-devel==2021.14.1
[pip] onemkl-sycl-blas==2025.0.1
[pip] onemkl-sycl-datafitting==2025.0.1
[pip] onemkl-sycl-dft==2025.0.1
[pip] onemkl-sycl-lapack==2025.0.1
[pip] onemkl-sycl-rng==2025.0.1
[pip] onemkl-sycl-sparse==2025.0.1
[pip] onemkl-sycl-stats==2025.0.1
[pip] onemkl-sycl-vm==2025.0.1
[pip] pytorch-triton-xpu==3.3.0
[pip] torch==2.7.0+xpu
[pip] torchaudio==2.7.0+xpu
[pip] torchvision==0.22.0+xpu
[pip] transformers==4.53.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions