Skip to content

Export llama3.1 Runtime error: Missing out variants: {'quantized_decomposed::dequantize_per_token'....... #7775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BodhiHu opened this issue Jan 20, 2025 · 8 comments

Comments

@BodhiHu
Copy link

BodhiHu commented Jan 20, 2025

🐛 Describe the bug

Hello, we got and runtime error when trying to export the llama3.1 8B model, here's the reproduce script:

#!/bin/bash

checkpoint=path/to/meta-llama-3.1-8b-instruct/original/consolidated.00.pth
params=path/to/meta-llama-3.1-8b-instruct/original/params.json
output_name="llama3_kv_sdpa_xnn_qe_4_32.pte"

python -m examples.models.llama.export_llama \
  --checkpoint "$checkpoint" \
  -p "$params" \
  -kv \
  --use_sdpa_with_kv_cache \
  -X \
  -qmode 8da4w \
  --group_size 128 \
  -d bf16 \
  --metadata '{"get_bos_id":128000, "get_eos_ids":[128009, 128001]}' \
  --embedding-quantize 4,32 \
  --output_name="$output_name"

Then we got error:

INFO:root:Failed converting '<EdgeOpOverload: quantized_decomposed.quantize_per_token.default>: schema = quantized_decomposed::quantize_per_token(Tensor input, Tensor scales, Tensor zero_points, int quant_min, int quant_max, ScalarType dtype) -> Tensor' to its out variant with error: 'SchemaKind.out variant of operator quantized_decomposed::quantize_per_token can't be found. We've found the schemas of all the overloads: ['quantized_decomposed::quantize_per_token(Tensor input, Tensor scales, Tensor zero_points, int quant_min, int quant_max, ScalarType dtype) -> Tensor']'
INFO:root:Failed converting '<EdgeOpOverload: quantized_decomposed.dequantize_per_token.default>: schema = quantized_decomposed::dequantize_per_token(Tensor input, Tensor scales, Tensor zero_points, int quant_min, int quant_max, ScalarType dtype, ScalarType output_dtype) -> Tensor' to its out variant with error: 'SchemaKind.out variant of operator quantized_decomposed::dequantize_per_token can't be found. We've found the schemas of all the overloads: ['quantized_decomposed::dequantize_per_token(Tensor input, Tensor scales, Tensor zero_points, int quant_min, int quant_max, ScalarType dtype, ScalarType output_dtype) -> Tensor']'
INFO:root:Failed converting '<EdgeOpOverload: quantized_decomposed.dequantize_per_channel_group.default>: schema = quantized_decomposed::dequantize_per_channel_group(Tensor input, Tensor scales, Tensor? zero_points, int quant_min, int quant_max, ScalarType dtype, int group_size, ScalarType output_dtype) -> Tensor' to its out variant with error: 'SchemaKind.out variant of operator quantized_decomposed::dequantize_per_channel_group can't be found. We've found the schemas of all the overloads: ['quantized_decomposed::dequantize_per_channel_group(Tensor input, Tensor scales, Tensor? zero_points, int quant_min, int quant_max, ScalarType dtype, int group_size, ScalarType output_dtype) -> Tensor']'
Traceback (most recent call last):
  File "/home/huaishun/miniconda3/envs/executorch/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/huaishun/miniconda3/envs/executorch/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/data/bodhihu/executorch/examples/models/llama/export_llama.py", line 32, in <module>
    main()  # pragma: no cover
  File "/data/bodhihu/executorch/examples/models/llama/export_llama.py", line 28, in main
    export_llama(args)
  File "/data/bodhihu/executorch/examples/models/llama/export_llama_lib.py", line 531, in export_llama
    builder = _export_llama(args)
  File "/data/bodhihu/executorch/examples/models/llama/export_llama_lib.py", line 817, in _export_llama
    builder = builder.to_executorch(passes=additional_passes)
  File "/home/huaishun/miniconda3/envs/executorch/lib/python3.10/site-packages/executorch/extension/llm/export/builder.py", line 439, in to_executorch
    self.export_program = self.edge_manager.to_executorch(
  File "/home/huaishun/miniconda3/envs/executorch/lib/python3.10/site-packages/executorch/exir/program/_program.py", line 93, in wrapper
    return func(self, *args, **kwargs)
  File "/home/huaishun/miniconda3/envs/executorch/lib/python3.10/site-packages/executorch/exir/program/_program.py", line 1364, in to_executorch
    new_gm_res = p(new_gm)
  File "/home/huaishun/miniconda3/envs/executorch/lib/python3.10/site-packages/torch/fx/passes/infra/pass_base.py", line 44, in __call__
    res = self.call(graph_module)
  File "/home/huaishun/miniconda3/envs/executorch/lib/python3.10/site-packages/executorch/exir/passes/__init__.py", line 427, in call
    raise RuntimeError(f"Missing out variants: {missing_out_vars}")
RuntimeError: Missing out variants: {'quantized_decomposed::dequantize_per_token', 'quantized_decomposed::choose_qparams_per_token_asymmetric', 'quantized_decomposed::dequantize_per_channel_group', 'quantized_decomposed::quantize_per_token'}

Versions

env:

(executorch) huaishun@apollo07:~/bodhihu/executorch$ python collect_env.py
Collecting environment information...
PyTorch version: 2.6.0.dev20250104+cpu
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: 17.0.6 (++20231209124227+6009708b4367-1~exp1~20231209124336.77)
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.10.0 (default, Mar  3 2022, 09:58:08) [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-6.2.0-1015-nvidia-x86_64-with-glibc2.35
Is CUDA available: False
CUDA runtime version: 12.6.77
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration:
GPU 0: NVIDIA GeForce RTX 3090
GPU 1: NVIDIA GeForce RTX 3090
GPU 2: NVIDIA GeForce RTX 3090
GPU 3: NVIDIA GeForce RTX 3090

Nvidia driver version: 560.35.03
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                       x86_64
CPU op-mode(s):                     32-bit, 64-bit
Address sizes:                      46 bits physical, 57 bits virtual
Byte Order:                         Little Endian
CPU(s):                             64
On-line CPU(s) list:                0-63
Vendor ID:                          GenuineIntel
Model name:                         Intel(R) Xeon(R) Gold 6346 CPU @ 3.10GHz
CPU family:                         6
Model:                              106
Thread(s) per core:                 2
Core(s) per socket:                 16
Socket(s):                          2
Stepping:                           6
CPU max MHz:                        3600.0000
CPU min MHz:                        800.0000
BogoMIPS:                           6200.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 pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect wbnoinvd dtherm ida arat pln pts avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities
Virtualization:                     VT-x
L1d cache:                          1.5 MiB (32 instances)
L1i cache:                          1 MiB (32 instances)
L2 cache:                           40 MiB (32 instances)
L3 cache:                           72 MiB (2 instances)
NUMA node(s):                       2
NUMA node0 CPU(s):                  0-15,32-47
NUMA node1 CPU(s):                  16-31,48-63
Vulnerability Gather data sampling: Vulnerable: No microcode
Vulnerability Itlb multihit:        Not affected
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Vulnerable: Clear CPU buffers attempted, no microcode; SMT vulnerable
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 IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Not affected

Versions of relevant libraries:
[pip3] executorch==0.6.0a0+fedb035
[pip3] numpy==2.0.0
[pip3] nvidia-cublas-cu12==12.1.3.1
[pip3] nvidia-cuda-cupti-cu12==12.1.105
[pip3] nvidia-cuda-nvrtc-cu12==12.1.105
[pip3] nvidia-cuda-runtime-cu12==12.1.105
[pip3] nvidia-cudnn-cu12==9.1.0.70
[pip3] nvidia-cufft-cu12==11.0.2.54
[pip3] nvidia-curand-cu12==10.3.2.106
[pip3] nvidia-cusolver-cu12==11.4.5.107
[pip3] nvidia-cusparse-cu12==12.1.0.106
[pip3] nvidia-nccl-cu12==2.20.5
[pip3] nvidia-nvjitlink-cu12==12.6.77
[pip3] nvidia-nvtx-cu12==12.1.105
[pip3] torch==2.6.0.dev20250104+cpu
[pip3] torchao==0.8.0+git11333ba2
[pip3] torchaudio==2.6.0.dev20250104+cpu
[pip3] torchsr==1.0.4
[pip3] torchvision==0.22.0.dev20250104+cpu
[pip3] triton==3.0.0
[conda] executorch                0.6.0a0+fedb035          pypi_0    pypi
[conda] numpy                     2.0.0                    pypi_0    pypi
[conda] torch                     2.6.0.dev20250104+cpu          pypi_0    pypi
[conda] torchao                   0.8.0+git11333ba2          pypi_0    pypi
[conda] torchaudio                2.6.0.dev20250104+cpu          pypi_0    pypi
[conda] torchsr                   1.0.4                    pypi_0    pypi
[conda] torchvision               0.22.0.dev20250104+cpu          pypi_0    pypi
@BodhiHu
Copy link
Author

BodhiHu commented Jan 20, 2025

Another thing is that, the memory required is very high when running the converting script ...
I had to switch to a Llama-3.2-1B-Instruct model to avoid OOM (with 16G memory on my machine)

@BodhiHu
Copy link
Author

BodhiHu commented Jan 21, 2025

Similar issues:
#3443
#6975

@BodhiHu
Copy link
Author

BodhiHu commented Jan 22, 2025

Added some debug logs, the SchemaKind is different even though it's the same name when converting op:

INFO:root:Failed converting '<EdgeOpOverload: quantized_decomposed.dequantize_per_token.default>: schema = quantized_decomposed::dequantize_per_token(Tensor input, Tensor scales, Tensor zero_points, int quant_min, int quant_max, ScalarType dtype, ScalarType output_dtype) -> Tensor' to its out variant with error: 'SchemaKind.out variant of operator quantized_decomposed::dequantize_per_token can't be found. We've found the schemas of all the overloads: ['quantized_decomposed::dequantize_per_token(Tensor input, Tensor scales, Tensor zero_points, int quant_min, int quant_max, ScalarType dtype, ScalarType output_dtype) -> Tensor']'
>>>>>>>>>
  SchemaKind.functional == SchemaKind.out:
    equals: False
  quantized_decomposed::dequantize_per_channel_group(Tensor input, Tensor scales, Tensor? zero_points, int quant_min, int quant_max, ScalarType dtype, int group_size, ScalarType output_dtype) -> ()
  quantized_decomposed::dequantize_per_channel_group(Tensor input, Tensor scales, Tensor? zero_points, int quant_min, int quant_max, ScalarType dtype, int group_size, ScalarType output_dtype) -> ()
    equals: True

@bluejack
Copy link

bluejack commented Jan 22, 2025

Also getting this error on the llama export attempting to quantize with these params; but perhaps I am missing a param?

The docs recommend using a pre-quantized model, but I am trying to better understand the executorch quantizing options for another model, but not quite sure what the correct params are, so this one might be my own error...

python -m examples.models.llama.export_llama \
  --model "llama3_2" \
  --checkpoint "${LLAMA_CHECKPOINT:?}" \
  --params "${LLAMA_PARAMS:?}" \
  --xnnpack \
  --xnnpack-extended-ops \
  --pt2e_quantize "xnnpack_dynamic_qc4" \
  -kv \
  --use_sdpa_with_kv_cache \
  -X \
  -d bf16 \
  --metadata '{"get_bos_id":128000, "get_eos_ids":[128009, 128001]}' \
  --output_name="llama3_2.pte"

swapping out the pt2e quantize param with -qmode "8da4w" does not fare any better.

Note, I also had to downgrade numpy from the executorch default to run this at all...


UPDATE: in my case, the -d bf16 parameter was not compatible with xnnpack; and switching that to fp16 was successful.

@jackzhxng
Copy link
Contributor

@cccclai @mcr229

@mcr229
Copy link
Contributor

mcr229 commented Jan 23, 2025

@BodhiHu yup as @bluejack mentioned XNNPACK doesn't currently have support for quantized bf16 kernels, so we don't support the bf16 datatype just yet, but fp16 should work. BF16 support is something we are working with the XNNPACK team on adding, so we hope to get that out soon.

@BodhiHu
Copy link
Author

BodhiHu commented Jan 24, 2025

Hi @mcr229 , thanks a lot for the help, I can now export the model to bpe with fp16.

However, when trying to run the model, I'm getting another tokenizer load error 😅:

(executorch) ~/bodhi/executorch$ cmake-out/examples/models/llama/llama_main \
  --model_path=./llama3_kv_sdpa_xnn_qe_4_32.pte \
  --tokenizer_path=~/models/Llama-3.2-1B-Instruct/original/tokenizer.model \
  --prompt="You are a helpful AI assistant."
I 00:00:00.002351 executorch:cpuinfo_utils.cpp:61] Reading file /sys/devices/soc0/image_version
I 00:00:00.002421 executorch:cpuinfo_utils.cpp:77] Failed to open midr file /sys/devices/soc0/image_version
I 00:00:00.002443 executorch:cpuinfo_utils.cpp:90] Reading file /sys/devices/system/cpu/cpu0/regs/identification/midr_el1
I 00:00:00.002517 executorch:cpuinfo_utils.cpp:90] Reading file /sys/devices/system/cpu/cpu1/regs/identification/midr_el1
I 00:00:00.002558 executorch:cpuinfo_utils.cpp:90] Reading file /sys/devices/system/cpu/cpu2/regs/identification/midr_el1
I 00:00:00.002591 executorch:cpuinfo_utils.cpp:90] Reading file /sys/devices/system/cpu/cpu3/regs/identification/midr_el1
I 00:00:00.002620 executorch:cpuinfo_utils.cpp:90] Reading file /sys/devices/system/cpu/cpu4/regs/identification/midr_el1
I 00:00:00.002651 executorch:cpuinfo_utils.cpp:90] Reading file /sys/devices/system/cpu/cpu5/regs/identification/midr_el1
I 00:00:00.002679 executorch:cpuinfo_utils.cpp:90] Reading file /sys/devices/system/cpu/cpu6/regs/identification/midr_el1
I 00:00:00.002708 executorch:cpuinfo_utils.cpp:90] Reading file /sys/devices/system/cpu/cpu7/regs/identification/midr_el1
I 00:00:00.002740 executorch:cpuinfo_utils.cpp:90] Reading file /sys/devices/system/cpu/cpu8/regs/identification/midr_el1
I 00:00:00.002771 executorch:cpuinfo_utils.cpp:90] Reading file /sys/devices/system/cpu/cpu9/regs/identification/midr_el1
I 00:00:00.002807 executorch:cpuinfo_utils.cpp:90] Reading file /sys/devices/system/cpu/cpu10/regs/identification/midr_el1
I 00:00:00.002837 executorch:cpuinfo_utils.cpp:90] Reading file /sys/devices/system/cpu/cpu11/regs/identification/midr_el1
I 00:00:00.002871 executorch:main.cpp:69] Resetting threadpool with num threads = 12
I 00:00:00.003889 executorch:runner.cpp:59] Creating LLaMa runner: model_path=./llama3_kv_sdpa_xnn_qe_4_32.pte, tokenizer_path=~/models/Llama-3.2-1B-Instruct/original/tokenizer.model
E 00:00:03.030818 executorch:tiktoken.cpp:96] failed to open encoder file: ~/models/Llama-3.2-1B-Instruct/original/tokenizer.model
I 00:00:03.030898 executorch:runner.cpp:82] Failed to load ~/models/Llama-3.2-1B-Instruct/original/tokenizer.model as a Tiktoken artifact, trying BPE tokenizer
E 00:00:03.030932 executorch:bpe_tokenizer.cpp:55] couldn't load ~/models/Llama-3.2-1B-Instruct/original/tokenizer.model
I 00:00:03.030938 executorch:runner.cpp:88] Reading metadata from model
I 00:00:03.031003 executorch:runner.cpp:113] Metadata: get_bos_id = 128000
I 00:00:03.031010 executorch:runner.cpp:113] Metadata: use_kv_cache = 1
I 00:00:03.031015 executorch:runner.cpp:113] Metadata: get_max_seq_len = 128
I 00:00:03.031020 executorch:runner.cpp:113] Metadata: get_vocab_size = 128256
I 00:00:03.031025 executorch:runner.cpp:113] Metadata: use_sdpa_with_kv_cache = 1
I 00:00:03.031030 executorch:runner.cpp:113] Metadata: enable_dynamic_shape = 1
I 00:00:03.031038 executorch:runner.cpp:120] eos_id = 128009
I 00:00:03.031042 executorch:runner.cpp:120] eos_id = 128001
I 00:00:03.031092 executorch:runner.cpp:174] RSS after loading model: 965.972656 MiB (0 if unsupported)
E 00:00:03.031135 executorch:bpe_tokenizer.cpp:176] Tokenizer not initialized
E 00:00:03.031139 executorch:runner.cpp:204] Failed to encode prompt You are a helpful AI assistant.

There seems be some errors when loading the tokenizer.model with both Tiktoken and BPE ...

[Update]
seems tokenizer_path needs to be abs path, i updated it to the absolute path and it can successfully run inference now:

--tokenizer_path=/home/mt/bodhi/models/Llama-3.2-1B-Instruct/original/tokenizer.model

@BodhiHu
Copy link
Author

BodhiHu commented Jan 24, 2025

really appreciate the helps here, i'm closing this now😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants