pytorch / executorch

On-device AI across mobile, embedded and edge for PyTorch
https://pytorch.org/executorch/
Other
1.44k stars 234 forks source link

Runtime error with mmap #3850

Closed rcontesti closed 1 month ago

rcontesti commented 1 month ago

Not sure if this is related to this previous issue 2907

But when following the Llama tutorial (link)[https://github.com/pytorch/executorch/blob/main/examples/models/llama2/README.md] to run llama3 with the following script

python3 -m examples.models.llama2.export_llama \
    --checkpoint ../llama3/Meta-Llama-3-8B_copy/consolidated.00.pth \
    -p ../llama3/Meta-Llama-3-8B_copy/params.json -kv \
    --use_sdpa_with_kv_cache -X -qmode 8da4w \
    --group_size 128 -d fp32 \
    --metadata '{"get_bos_id":128000, "get_eos_id":128001}' \
    --embedding-quantize 4,32 \
    --output_name="llama3_kv_sdpa_xnn_qe_4_32.pte"

I'm getting the following runtime error:

Could not import fairseq2 modules.
INFO:root:Loading model with checkpoint=../llama3/Meta-Llama-3-8B_copy/consolidated.00.pth, params=../llama3/Meta-Llama-3-8B_copy/params.json, use_kv_cache=True, weight_type=WeightType.LLAMA
Traceback (most recent call last):
  File "/home/ruben/anaconda3/envs/executorch/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/ruben/anaconda3/envs/executorch/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/ruben/code/executorch/examples/models/llama2/export_llama.py", line 30, in <module>
    main()  # pragma: no cover
  File "/home/ruben/code/executorch/examples/models/llama2/export_llama.py", line 26, in main
    export_llama(modelname, args)
  File "/home/ruben/code/executorch/examples/models/llama2/export_llama_lib.py", line 545, in export_llama
    return _export_llama(modelname, args)
  File "/home/ruben/code/executorch/examples/models/llama2/export_llama_lib.py", line 707, in _export_llama
    builder_exported_to_edge = _prepare_for_llama_export(
  File "/home/ruben/code/executorch/examples/models/llama2/export_llama_lib.py", line 629, in _prepare_for_llama_export
    load_llama_model(
  File "/home/ruben/code/executorch/examples/models/llama2/builder.py", line 83, in load_llama_model
    model, example_inputs, _ = EagerModelFactory.create_model(
  File "/home/ruben/code/executorch/examples/models/model_factory.py", line 44, in create_model
    model = model_class(**kwargs)
  File "/home/ruben/code/executorch/examples/models/llama2/model.py", line 75, in __init__
    checkpoint = torch.load(checkpoint_path, map_location=device, mmap=True)
  File "/home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages/torch/serialization.py", line 1078, in load
    raise RuntimeError("mmap can only be used with files saved with "
RuntimeError: mmap can only be used with files saved with `torch.save(../llama3/Meta-Llama-3-8B_copy/consolidated.00.pth, _use_new_zipfile_serialization=True), please torch.save your checkpoint with this option in order to use mmap.

I'm using the following environment

python3 -m torch.utils.collect_env
/home/ruben/anaconda3/envs/executorch/lib/python3.10/runpy.py:126: RuntimeWarning: 'torch.utils.collect_env' found in sys.modules after import of package 'torch.utils', but prior to execution of 'torch.utils.collect_env'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))
Collecting environment information...
PyTorch version: 2.4.0.dev20240507+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.1 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.29.3
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.5.0-35-generic-x86_64-with-glibc2.35
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
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:                      39 bits physical, 48 bits virtual
Byte Order:                         Little Endian
CPU(s):                             4
On-line CPU(s) list:                0-3
Vendor ID:                          GenuineIntel
Model name:                         Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
CPU family:                         6
Model:                              142
Thread(s) per core:                 2
Core(s) per socket:                 2
Socket(s):                          1
Stepping:                           9
CPU max MHz:                        4000,0000
CPU min MHz:                        400,0000
BogoMIPS:                           6999.82
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 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 invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp vnmi md_clear flush_l1d arch_capabilities
Virtualization:                     VT-x
L1d cache:                          64 KiB (2 instances)
L1i cache:                          64 KiB (2 instances)
L2 cache:                           512 KiB (2 instances)
L3 cache:                           4 MiB (1 instance)
NUMA node(s):                       1
NUMA node0 CPU(s):                  0-3
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit:        KVM: Mitigation: VMX disabled
Vulnerability L1tf:                 Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds:                  Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:             Mitigation; PTI
Vulnerability Mmio stale data:      Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:             Mitigation; IBRS
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; IBRS; IBPB conditional; STIBP conditional; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                Mitigation; Microcode
Vulnerability Tsx async abort:      Not affected

Versions of relevant libraries:
[pip3] executorch==0.3.0a0+9d58de1
[pip3] numpy==1.26.4
[pip3] torch==2.4.0.dev20240507+cpu
[pip3] torchao==0.1
[pip3] torchaudio==2.2.0.dev20240507+cpu
[pip3] torchsr==1.0.4
[pip3] torchvision==0.19.0.dev20240507+cpu
[pip3] triton==2.3.0
[conda] executorch                0.3.0a0+9d58de1          pypi_0    pypi
[conda] torch                     2.4.0.dev20240507+cpu          pypi_0    pypi
[conda] torchao                   0.1                      pypi_0    pypi
[conda] torchaudio                2.2.0.dev20240507+cpu          pypi_0    pypi
[conda] torchsr                   1.0.4                    pypi_0    pypi
[conda] torchvision               0.19.0.dev20240507+cpu          pypi_0    pypi
mergennachin commented 1 month ago

@rcontesti which branch are you using? main branch or release branch?

rcontesti commented 1 month ago

I'm using the main branch. I just cloned following the instructions of (Getting started)[https://pytorch.org/executorch/main/getting-started-setup] with git clone https://github.com/pytorch/executorch.git

lucylq commented 1 month ago

Thanks for adding repro instructions and your environment @rcontesti !

I just tried the command on the same commit (9d58de1), and can export Llama3 8B/8B-Instruct and stories (the failure reported in https://github.com/pytorch/executorch/issues/2907). Your environment looks good. To make sure I have the right repro, which Llama3 8B model are you using (8B/8B-Instruct?) and where is it from (Meta official website, HF?)

As a workaround, could you try removing mmap=True from https://github.com/pytorch/executorch/blob/main/examples/models/llama2/model.py#L111 and see if that works?

rcontesti commented 1 month ago

Hi @lucylq, thanks for the support

I'm using LLama3 8B (Not 8B-Instruct). I'm downloading with meta link sent to my email. I'm also trying to run it with --branch v0.2.0. The problem is that with v0.20.0 now I cannot run: $./install_requirements.sh --pybind xnnpack as I'm getting the following error which is basically issue (3674)[https://github.com/pytorch/executorch/issues/3764]:

Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/test/cpu
Collecting torch==2.3.0
  Downloading https://download.pytorch.org/whl/test/cpu/torch-2.3.0%2Bcpu-cp310-cp310-linux_x86_64.whl (190.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 190.4/190.4 MB 2.8 MB/s eta 0:00:00
Collecting torchvision==0.18.0
  Using cached https://download.pytorch.org/whl/test/cpu/torchvision-0.18.0%2Bcpu-cp310-cp310-linux_x86_64.whl (1.6 MB)
Requirement already satisfied: cmake in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (3.29.3)
Requirement already satisfied: pyyaml in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (6.0.1)
Requirement already satisfied: setuptools in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (69.5.1)
Requirement already satisfied: tomli in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (2.0.1)
Requirement already satisfied: wheel in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (0.43.0)
Requirement already satisfied: zstd in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (1.5.5.1)
Requirement already satisfied: timm==0.6.13 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (0.6.13)
Collecting torchaudio==2.3.0
  Using cached https://download.pytorch.org/whl/test/cpu/torchaudio-2.3.0%2Bcpu-cp310-cp310-linux_x86_64.whl (1.7 MB)
Requirement already satisfied: torchsr==1.0.4 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (1.0.4)
Requirement already satisfied: transformers==4.38.2 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (4.38.2)
Requirement already satisfied: filelock in /home/ruben/.local/lib/python3.10/site-packages (from torch==2.3.0) (3.14.0)
Requirement already satisfied: typing-extensions>=4.8.0 in /home/ruben/.local/lib/python3.10/site-packages (from torch==2.3.0) (4.11.0)
Requirement already satisfied: sympy in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from torch==2.3.0) (1.12.1)
Requirement already satisfied: networkx in /home/ruben/.local/lib/python3.10/site-packages (from torch==2.3.0) (3.3)
Requirement already satisfied: jinja2 in /home/ruben/.local/lib/python3.10/site-packages (from torch==2.3.0) (3.1.4)
Requirement already satisfied: fsspec in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from torch==2.3.0) (2024.3.1)
Requirement already satisfied: numpy in /home/ruben/.local/lib/python3.10/site-packages (from torchvision==0.18.0) (1.26.4)
Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from torchvision==0.18.0) (10.3.0)
Requirement already satisfied: huggingface-hub in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from timm==0.6.13) (0.23.3)
Requirement already satisfied: packaging>=20.0 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from transformers==4.38.2) (24.0)
Requirement already satisfied: regex!=2019.12.17 in /home/ruben/.local/lib/python3.10/site-packages (from transformers==4.38.2) (2024.5.15)
Requirement already satisfied: requests in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from transformers==4.38.2) (2.32.3)
Requirement already satisfied: tokenizers<0.19,>=0.14 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from transformers==4.38.2) (0.15.2)
Requirement already satisfied: safetensors>=0.4.1 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from transformers==4.38.2) (0.4.3)
Requirement already satisfied: tqdm>=4.27 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from transformers==4.38.2) (4.66.4)
Requirement already satisfied: MarkupSafe>=2.0 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from jinja2->torch==2.3.0) (2.1.5)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/ruben/.local/lib/python3.10/site-packages (from requests->transformers==4.38.2) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from requests->transformers==4.38.2) (3.7)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from requests->transformers==4.38.2) (2.2.1)
Requirement already satisfied: certifi>=2017.4.17 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from requests->transformers==4.38.2) (2024.6.2)
Requirement already satisfied: mpmath<1.4.0,>=1.1.0 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from sympy->torch==2.3.0) (1.3.0)
Installing collected packages: torch, torchvision, torchaudio
  Attempting uninstall: torch
    Found existing installation: torch 2.4.0.dev20240507+cpu
    Uninstalling torch-2.4.0.dev20240507+cpu:
      Successfully uninstalled torch-2.4.0.dev20240507+cpu
  Attempting uninstall: torchvision
    Found existing installation: torchvision 0.19.0.dev20240507+cpu
    Uninstalling torchvision-0.19.0.dev20240507+cpu:
      Successfully uninstalled torchvision-0.19.0.dev20240507+cpu
  Attempting uninstall: torchaudio
    Found existing installation: torchaudio 2.2.0.dev20240507+cpu
    Uninstalling torchaudio-2.2.0.dev20240507+cpu:
      Successfully uninstalled torchaudio-2.2.0.dev20240507+cpu
Successfully installed torch-2.3.0+cpu torchaudio-2.3.0+cpu torchvision-0.18.0+cpu
Using pip 24.0 from /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages/pip (python 3.10)
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/test/cpu
Processing /home/ruben/code/localllm/executorch
  Running command Preparing metadata (pyproject.toml)
  running dist_info
  creating /tmp/pip-modern-metadata-uhnfv73u/executorch.egg-info
  writing /tmp/pip-modern-metadata-uhnfv73u/executorch.egg-info/PKG-INFO
  writing dependency_links to /tmp/pip-modern-metadata-uhnfv73u/executorch.egg-info/dependency_links.txt
  writing entry points to /tmp/pip-modern-metadata-uhnfv73u/executorch.egg-info/entry_points.txt
  writing requirements to /tmp/pip-modern-metadata-uhnfv73u/executorch.egg-info/requires.txt
  writing top-level names to /tmp/pip-modern-metadata-uhnfv73u/executorch.egg-info/top_level.txt
  writing manifest file '/tmp/pip-modern-metadata-uhnfv73u/executorch.egg-info/SOURCES.txt'
  reading manifest file '/tmp/pip-modern-metadata-uhnfv73u/executorch.egg-info/SOURCES.txt'
  adding license file 'LICENSE'
  writing manifest file '/tmp/pip-modern-metadata-uhnfv73u/executorch.egg-info/SOURCES.txt'
  creating '/tmp/pip-modern-metadata-uhnfv73u/executorch-0.2.0a0+4f79832.dist-info'
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: expecttest in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from executorch==0.2.0a0+4f79832) (0.2.1)
Requirement already satisfied: flatbuffers in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from executorch==0.2.0a0+4f79832) (24.3.25)
Requirement already satisfied: hypothesis in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from executorch==0.2.0a0+4f79832) (6.103.0)
Requirement already satisfied: numpy in /home/ruben/.local/lib/python3.10/site-packages (from executorch==0.2.0a0+4f79832) (1.26.4)
Requirement already satisfied: packaging in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from executorch==0.2.0a0+4f79832) (24.0)
Requirement already satisfied: pandas in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from executorch==0.2.0a0+4f79832) (2.2.2)
Requirement already satisfied: parameterized in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from executorch==0.2.0a0+4f79832) (0.9.0)
Requirement already satisfied: pytest in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from executorch==0.2.0a0+4f79832) (8.2.2)
Requirement already satisfied: pytest-xdist in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from executorch==0.2.0a0+4f79832) (3.6.1)
Requirement already satisfied: pyyaml in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from executorch==0.2.0a0+4f79832) (6.0.1)
Requirement already satisfied: ruamel.yaml in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from executorch==0.2.0a0+4f79832) (0.18.6)
Requirement already satisfied: sympy in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from executorch==0.2.0a0+4f79832) (1.12.1)
Requirement already satisfied: tabulate in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from executorch==0.2.0a0+4f79832) (0.9.0)
Requirement already satisfied: torch==2.3 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from executorch==0.2.0a0+4f79832) (2.3.0+cpu)
Requirement already satisfied: filelock in /home/ruben/.local/lib/python3.10/site-packages (from torch==2.3->executorch==0.2.0a0+4f79832) (3.14.0)
Requirement already satisfied: typing-extensions>=4.8.0 in /home/ruben/.local/lib/python3.10/site-packages (from torch==2.3->executorch==0.2.0a0+4f79832) (4.11.0)
Requirement already satisfied: networkx in /home/ruben/.local/lib/python3.10/site-packages (from torch==2.3->executorch==0.2.0a0+4f79832) (3.3)
Requirement already satisfied: jinja2 in /home/ruben/.local/lib/python3.10/site-packages (from torch==2.3->executorch==0.2.0a0+4f79832) (3.1.4)
Requirement already satisfied: fsspec in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from torch==2.3->executorch==0.2.0a0+4f79832) (2024.3.1)
Requirement already satisfied: attrs>=22.2.0 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from hypothesis->executorch==0.2.0a0+4f79832) (23.2.0)
Requirement already satisfied: sortedcontainers<3.0.0,>=2.1.0 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from hypothesis->executorch==0.2.0a0+4f79832) (2.4.0)
Requirement already satisfied: exceptiongroup>=1.0.0 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from hypothesis->executorch==0.2.0a0+4f79832) (1.2.1)
Requirement already satisfied: python-dateutil>=2.8.2 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from pandas->executorch==0.2.0a0+4f79832) (2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from pandas->executorch==0.2.0a0+4f79832) (2024.1)
Requirement already satisfied: tzdata>=2022.7 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from pandas->executorch==0.2.0a0+4f79832) (2024.1)
Requirement already satisfied: iniconfig in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from pytest->executorch==0.2.0a0+4f79832) (2.0.0)
Requirement already satisfied: pluggy<2.0,>=1.5 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from pytest->executorch==0.2.0a0+4f79832) (1.5.0)
Requirement already satisfied: tomli>=1 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from pytest->executorch==0.2.0a0+4f79832) (2.0.1)
Requirement already satisfied: execnet>=2.1 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from pytest-xdist->executorch==0.2.0a0+4f79832) (2.1.1)
Requirement already satisfied: ruamel.yaml.clib>=0.2.7 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from ruamel.yaml->executorch==0.2.0a0+4f79832) (0.2.8)
Requirement already satisfied: mpmath<1.4.0,>=1.1.0 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from sympy->executorch==0.2.0a0+4f79832) (1.3.0)
Requirement already satisfied: six>=1.5 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from python-dateutil>=2.8.2->pandas->executorch==0.2.0a0+4f79832) (1.16.0)
Requirement already satisfied: MarkupSafe>=2.0 in /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages (from jinja2->torch==2.3->executorch==0.2.0a0+4f79832) (2.1.5)
Building wheels for collected packages: executorch
  Running command Building wheel for executorch (pyproject.toml)
  running bdist_wheel
  running build
  command options for 'CustomBuild':
    build_base = pip-out
    build_purelib = pip-out/lib
    build_platlib = pip-out/lib.linux-x86_64-cpython-310
    build_lib = pip-out/lib.linux-x86_64-cpython-310
    build_scripts = pip-out/scripts-3.10
    build_temp = pip-out/temp.linux-x86_64-cpython-310
    plat_name = linux-x86_64
    compiler = None
    parallel = 3
    debug = None
    force = None
    executable = /home/ruben/anaconda3/envs/executorch/bin/python
  creating /home/ruben/code/localllm/executorch/pip-out
  creating /home/ruben/code/localllm/executorch/pip-out/temp.linux-x86_64-cpython-310
  creating /home/ruben/code/localllm/executorch/pip-out/temp.linux-x86_64-cpython-310/cmake-out
  deleting /home/ruben/code/localllm/executorch/pip-out/temp.linux-x86_64-cpython-310/cmake-out/CMakeCache.txt
  cmake -S /home/ruben/code/localllm/executorch -B /home/ruben/code/localllm/executorch/pip-out/temp.linux-x86_64-cpython-310/cmake-out -DBUCK2= -DPYTHON_EXECUTABLE=/home/ruben/anaconda3/envs/executorch/bin/python -DCMAKE_PREFIX_PATH=/home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages -DCMAKE_BUILD_TYPE=Release -DEXECUTORCH_ENABLE_LOGGING=ON -DEXECUTORCH_LOG_LEVEL=Info -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DEXECUTORCH_SEPARATE_FLATCC_HOST_PROJECT=OFF -DEXECUTORCH_BUILD_PYBIND=ON -DEXECUTORCH_BUILD_XNNPACK=ON
  -- The C compiler identification is GNU 11.4.0
  -- The CXX compiler identification is GNU 11.4.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/bin/cc - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Check for working CXX compiler: /usr/bin/c++ - skipped
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
  -- Found Threads: TRUE
  -- Downloading FXdiv to /home/ruben/code/localllm/executorch/pip-out/temp.linux-x86_64-cpython-310/cmake-out/FXdiv-source (define FXDIV_SOURCE_DIR to avoid it)
  -- Configuring done (0.0s)
  -- Generating done (0.0s)
  -- Build files have been written to: /home/ruben/code/localllm/executorch/pip-out/temp.linux-x86_64-cpython-310/cmake-out/FXdiv-download
  [ 11%] Creating directories for 'fxdiv'
  [ 22%] Performing download step (git clone) for 'fxdiv'
  Cloning into 'FXdiv-source'...
  Already on 'master'
  Your branch is up to date with 'origin/master'.
  [ 33%] Performing update step for 'fxdiv'
  [ 44%] No patch step for 'fxdiv'
  [ 55%] No configure step for 'fxdiv'
  [ 66%] No build step for 'fxdiv'
  [ 77%] No install step for 'fxdiv'
  [ 88%] No test step for 'fxdiv'
  [100%] Completed 'fxdiv'
  [100%] Built target fxdiv
  -- Using python executable '/home/ruben/anaconda3/envs/executorch/bin/python'
  -- Resolved buck2 as /home/ruben/code/localllm/executorch/pip-out/temp.linux-x86_64-cpython-310/cmake-out/buck2-bin/buck2-071372cfde6e9936c62eb92823742392af4a945570df5c5b34d3eed1b03813c3.
  -- Killing buck2 daemon
  -- executorch: Generating source lists
  -- executorch: Generating source file list /home/ruben/code/localllm/executorch/pip-out/temp.linux-x86_64-cpython-310/cmake-out/executorch_srcs.cmake
  Error while generating /home/ruben/code/localllm/executorch/pip-out/temp.linux-x86_64-cpython-310/cmake-out/executorch_srcs.cmake. Exit code: 1
  Output:

  Error:
  Traceback (most recent call last):
    File "/home/ruben/code/localllm/executorch/build/buck_util.py", line 26, in run
      cp: subprocess.CompletedProcess = subprocess.run(
    File "/home/ruben/anaconda3/envs/executorch/lib/python3.10/subprocess.py", line 524, in run
      raise CalledProcessError(retcode, process.args,
  subprocess.CalledProcessError: Command '['/home/ruben/code/localllm/executorch/pip-out/temp.linux-x86_64-cpython-310/cmake-out/buck2-bin/buck2-071372cfde6e9936c62eb92823742392af4a945570df5c5b34d3eed1b03813c3', 'cquery', "inputs(deps('//runtime/executor:program'))"]' returned non-zero exit status 2.

  The above exception was the direct cause of the following exception:

  Traceback (most recent call last):
    File "/home/ruben/code/localllm/executorch/build/extract_sources.py", line 218, in <module>
      main()
    File "/home/ruben/code/localllm/executorch/build/extract_sources.py", line 203, in main
      target_to_srcs[name] = sorted(target.get_sources(graph, runner))
    File "/home/ruben/code/localllm/executorch/build/extract_sources.py", line 116, in get_sources
      sources: set[str] = set(runner.run(["cquery", query]))
    File "/home/ruben/code/localllm/executorch/build/buck_util.py", line 31, in run
      raise RuntimeError(ex.stderr.decode("utf-8")) from ex
  RuntimeError: [2024-06-05T18:16:26.962-03:00] buck2 daemon constraint mismatch: Version mismatch; killing daemon...
  [2024-06-05T18:16:27.066-03:00] Starting new buck2 daemon...
  [2024-06-05T18:16:27.483-03:00] Connected to new buck2 daemon.
  [2024-06-05T18:16:27.527-03:00] Build ID: a4d1e731-e834-4e30-99db-2b4e9ed2b0d2
  [2024-06-05T18:16:27.888-03:00] Soft Error: source_file_missing: Source file `gflags/src/gflags_declare.h.in` does not exist as a member of package `root//third-party`.
  Command failed:
  Error looking up configured node root//runtime/executor:program (prelude//platforms:default#524f8da68ea2a374)

  Caused by:
      0: Error looking up configured node root//runtime/executor:program_no_prim_ops (prelude//platforms:default#524f8da68ea2a374)
      1: Error looking up configured node root//schema:program (prelude//platforms:default#524f8da68ea2a374)
      2: Error looking up configured node root//schema:generate_program (prelude//platforms:default#524f8da68ea2a374)
      3: Error looking up configured node root//third-party:flatc (prelude//platforms:default#524f8da68ea2a374)
      4: looking up unconfigured target node `root//third-party:flatc`
      5: Error loading targets in package `root//third-party` for target `root//third-party:flatc`
      6: Error evaluating build file: `root//third-party:TARGETS`
      7: Traceback (most recent call last):
           * third-party/TARGETS:9, in <module>
               define_gflags()
           * third-party/gflags.bzl:5, in define_gflags
               (exported_headers, headers, srcs) = gflags_sources(namespace = [
           * third-party/gflags_defs.bzl:8, in gflags_sources
               native.genrule(
         error: Error coercing attribute `srcs` of `root//third-party:gflags_declare_h`
           --> third-party/gflags_defs.bzl:8:5
            |
          8 |       native.genrule(
            |  _____^
          9 | |         name = "gflags_declare_h",
         10 | |         srcs = ["gflags/src/gflags_declare.h.in"],
         11 | |         out = "gflags/gflags_declare.h",
         12 | |         cmd = (common_preamble + "awk '{ " +
         13 | |                "gsub(/@GFLAGS_NAMESPACE@/, \"" + namespace[0] + "\"); " +
         14 | |                "gsub(/@(HAVE_STDINT_H|HAVE_SYS_TYPES_H|HAVE_INTTYPES_H|GFLAGS_INTTYPES_FORMAT_C99)@/, \"1\"); " +
         15 | |                "gsub(/@([A-Z0-9_]+)@/, \"0\"); " +
         16 | |                "print; }' $SRCS > $OUT"),
         17 | |     )
            | |_____^
            |

      8: Error coercing attribute `srcs` of type `attrs.one_of(attrs.dict(attrs.string(), attrs.source(), sorted=False), attrs.list(attrs.source()), default=[])`
      9: Error coercing ["gflags/src/gflags_declare.h.in"]
     10: one_of fails, the errors against each alternative in turn were:
         Expected value of type `dict`, got value with type `list` (value was `["gflags/src/gflags_declare.h.in"]`)
         Error coercing "gflags/src/gflags_declare.h.in": Couldn't coerce `gflags/src/gflags_declare.h.in` as a source.
           Error when treated as a target: Invalid absolute target pattern `gflags/src/gflags_declare.h.in` is not allowed: Expected a `:`, a trailing `/...` or the literal `...`.: Expected a `:`, a trailing `/...` or the literal `...`.: Expected a `:`, a trailing `/...` or the literal `...`.
           Error when treated as a path: Source file `gflags/src/gflags_declare.h.in` does not exist as a member of package `root//third-party`.

  CMake Error at build/Utils.cmake:161 (message):
    executorch: source list generation failed
  Call Stack (most recent call first):
    CMakeLists.txt:261 (extract_sources)

  -- Configuring incomplete, errors occurred!
  error: command '/home/ruben/anaconda3/envs/executorch/bin/cmake' failed with exit code 1
  error: subprocess-exited-with-error

  × Building wheel for executorch (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /home/ruben/anaconda3/envs/executorch/bin/python /home/ruben/anaconda3/envs/executorch/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py build_wheel /tmp/tmp32jn8jmh
  cwd: /home/ruben/code/localllm/executorch
  Building wheel for executorch (pyproject.toml) ... error
  ERROR: Failed building wheel for executorch
Failed to build executorch
ERROR: Could not build wheels for executorch, which is required to install pyproject.toml-based projects
lucylq commented 1 month ago

Ah - for Llama3, we have to use the main branch. The release branch doesn't contain all the features required to export Llama3. It looks like that warning was removed from the documentation - will add it back in, thanks for pointing it out ~

Edit: though, I don't think we should see errors when installing ExecuTorch on the release branch. @GregoryComer looks like the buck2 resolver?

rcontesti commented 1 month ago

Hi team, once again many thanks for the support.

I returned to the main branch as suggested and reinstalled llama3 8B.

The process is killed without generating any pte file. I'm not getting much verbosity from the message.

I'm running

python3 -m examples.models.llama2.export_llama \
    --checkpoint ../llama3/Meta-Llama-3-8B/consolidated.00.pth \
    -p ../llama3/Meta-Llama-3-8B/params.json -kv \
    --use_sdpa_with_kv_cache -X -qmode 8da4w \
    --group_size 128 -d fp32 \
    --metadata '{"get_bos_id":128000, "get_eos_id":128001}' \
    --embedding-quantize 4,32 \
    --output_name="llama3_kv_sdpa_xnn_qe_4_32.pte"

And getting

[INFO 2024-06-06 11:19:55,094 export_llama_lib.py:390] Applying quantizers: []
[INFO 2024-06-06 11:19:55,094 builder.py:91] Loading model with checkpoint=../llama3/Meta-Llama-3-8B/consolidated.00.pth, params=../llama3/Meta-Llama-3-8B/params.json, use_kv_cache=True, weight_type=WeightType.LLAMA
[INFO 2024-06-06 11:19:55,404 builder.py:112] Loaded model with dtype=torch.bfloat16
[INFO 2024-06-06 11:19:55,405 builder.py:197] model.to torch.float32
Killed

It seems I'm exciding memory with Torch, which is strange as I have 32gb. Anyway I will try in a larger machine. Any suggestions in terms of memory optimization?

mergennachin commented 1 month ago

@rcontesti yeah my local machine is 32gb. it is pretty tight. i had to close some running applications to make the script work.

during export, the peak memory becomes somewhat high.

rcontesti commented 1 month ago

Thank @mergennachin. I'm closing the isse since the topic has drifted quite a bit. QQ: Is there anyway to make the export process take longer so that I could be handled with less memory? Since the export process is the peak demand of memory and is usually a one-off and I don't care how long it takes. Most of us I guess are mostly concern about run time once the graph is flattened. Anyway many thanks!