-
Notifications
You must be signed in to change notification settings - Fork 687
Summary: Add the Cross compilation Script for RPi (4 & 5) for Linux host machine #15014
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/15014
Note: Links to docs will display an error until the docs builds have been completed. ❌ 7 New Failures, 1 Unrelated FailureAs of commit a42b3a8 with merge base 45336ce ( NEW FAILURES - The following jobs have failed:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
parse_args() { | ||
while [[ $# -gt 0 ]]; do | ||
case $1 in | ||
pi4|pi5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't tested, It should work theoretically
examples/raspberry_pi/rpi_setup.sh
Outdated
--bundled-glibc Bundle toolchain GLIBC libraries (default) | ||
--no-bundled-glibc Use system GLIBC (requires RPi GLIBC upgrade) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--bundled-glibc Bundle toolchain GLIBC libraries (default) | |
--no-bundled-glibc Use system GLIBC (requires RPi GLIBC upgrade) | |
--no-bundled-glibc Use system GLIBC (may require RPi GLIBC upgrade) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the entire bundled-glibc option to make the script simple. These steps are detailed out clearly in the tutorial under trouble shooting section.
examples/raspberry_pi/rpi_setup.sh
Outdated
pi4|pi5 Target Raspberry Pi model | ||
|
||
Options: | ||
--bundled-glibc Bundle toolchain GLIBC libraries (default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this the default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this option completely as it is making the setup on Rpi complicated,
examples/raspberry_pi/rpi_setup.sh
Outdated
--force-rebuild Force complete rebuild of all components | ||
--force-download Force re-download of the ARM toolchain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--force-rebuild Force complete rebuild of all components | |
--force-download Force re-download of the ARM toolchain | |
--force-rebuild Force complete rebuild of all components | |
--force-download Force re-download of the ARM toolchain (default: disabled) |
@@ -0,0 +1,723 @@ | |||
#!/usr/bin/env bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/rpi_setup.sh/setup.sh
examples/raspberry_pi/rpi_setup.sh
Outdated
arm64|aarch64) | ||
if [[ "$HOST_OS" == "Darwin" ]]; then | ||
HOST_ARCH="x86_64" # Use x86_64 toolchain on Apple Silicon via Rosetta | ||
log_info "Using x86_64 toolchain via Rosetta on Apple Silicon" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how are we going to test this?
we can drop this tbh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
examples/raspberry_pi/rpi_setup.sh
Outdated
cd "$TOOLCHAIN_DIR" | ||
|
||
# Download toolchain | ||
if ! curl -L -o "$toolchain_archive" "$toolchain_url"; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check md5sum for the tarball?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
examples/raspberry_pi/rpi_setup.sh
Outdated
arch_flags="-march=armv8-a -mtune=cortex-a72" | ||
;; | ||
pi5) | ||
arch_flags="-march=armv8.2-a+dotprod+fp16" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add mtune? Does it have fp16?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, Raspberry Pi 5 fully supports FP16 and mtune too, (added mtune)
examples/raspberry_pi/rpi_setup.sh
Outdated
cp "$toolchain_lib_dir"/libc.so.* "$bundle_dir/" 2>/dev/null || true | ||
cp "$toolchain_lib_dir"/libm.so.* "$bundle_dir/" 2>/dev/null || true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally we should check et libs and see what all they depend on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed glibc post setup steps from the script to keep it simple
examples/raspberry_pi/rpi_setup.sh
Outdated
|
||
log_warning "Use bundled GLIBC script on RPI device ONLY if you encounter a GLIBC mismatch error when running llama_main." | ||
# Create deployment script | ||
cat > "$bundle_dir/install_libs.sh" << 'EOF' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this not a static file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer needed , as I removed glibc option
examples/raspberry_pi/rpi_setup.sh
Outdated
if command -v nm &> /dev/null; then | ||
if nm "$CMAKE_OUT_DIR/examples/models/llama/llama_main" 2>/dev/null | grep -q "extension"; then | ||
log_info "📦 libextension_module.a is statically linked into llama_main" | ||
static_linked=true | ||
fi | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we are building and linking it why do we have to do this? we should already know static or dynamic, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, removed all this logic, It is staically linked by default
examples/raspberry_pi/rpi_setup.sh
Outdated
echo " • libllama_runner.so: $CMAKE_OUT_DIR/examples/models/llama/runner/libllama_runner.so" | ||
|
||
# Smart extension module reporting | ||
if [[ "$EXTENSION_STATIC_LINKED" == "true" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's just pick one and simplify all this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
examples/raspberry_pi/rpi_setup.sh
Outdated
echo -e "\n📋 Next steps:" | ||
|
||
echo "1. Copy binaries to your Raspberry Pi $RPI_MODEL:" | ||
echo " scp $CMAKE_OUT_DIR/examples/models/llama/llama_main pi@<rpi-ip>:~/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change ~/
into some named dir to avoid making mess in the home dir
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
examples/raspberry_pi/rpi_setup.sh
Outdated
fi | ||
|
||
echo -e "\n2. Copy shared libraries to system location:" | ||
echo " sudo cp libllama_runner.so /lib/ # Only this one needed!" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we want to put under /lib
? Just put it in the same dir ~/
and set LD_LIBRARY_PATH
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
examples/raspberry_pi/rpi_setup.sh
Outdated
# Create environment setup script | ||
cat > "$SCRIPT_DIR/setup_env.sh" << 'ENVEOF' | ||
#!/bin/bash | ||
export LD_LIBRARY_PATH="/usr/local/lib/executorch:$LD_LIBRARY_PATH" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/usr/local/lib
should already be on LD_LIBRARY_PATH
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I haven't tried it on my machine yet..
…ost machine Test Plan: examples/raspberry_pi/setup.sh pi5 ... [100%] Linking CXX executable llama_main [100%] Built target llama_main [SUCCESS] LLaMA runner built successfully ==== Verifying Build Outputs ==== [INFO] Checking required binaries... [SUCCESS] ✓ llama_main (6.1M) [SUCCESS] ✓ libllama_runner.so (4.0M) [SUCCESS] ✓ libextension_module.a (89K) - static library [SUCCESS] All required binaries built successfully! ==== Setup Complete! ==== ✓ ExecuTorch cross-compilation setup completed successfully! 📦 Built binaries: • llama_main: /home/sidart/working/executorch/cmake-out/examples/models/llama/llama_main • libllama_runner.so: /home/sidart/working/executorch/cmake-out/examples/models/llama/runner/libllama_runner.so • libextension_module.a: Statically linked into llama_main ✅ • Bundled libraries: /home/sidart/working/executorch/cmake-out/bundled-libs/ 📋 Next steps: 1. Copy binaries to your Raspberry Pi pi5: scp /home/sidart/working/executorch/cmake-out/examples/models/llama/llama_main pi@<rpi-ip>:~/ scp /home/sidart/working/executorch/cmake-out/examples/models/llama/runner/libllama_runner.so pi@<rpi-ip>:~/ scp -r /home/sidart/working/executorch/cmake-out/bundled-libs/ pi@<rpi-ip>:~/ 2. Copy shared libraries to system location: sudo cp libllama_runner.so /lib/ # Only this one needed! sudo ldconfig 3. Dry run to check for GLIBC or other issues: ./llama_main --help # Ensure there are no GLIBC or other errors before proceeding. 4. Download your model and tokenizer: # Refer to the official documentation for exact details. 5. Run ExecuTorch with your model: ./llama_main --model_path ./model.pte --tokenizer_path ./tokenizer.model --seq_len 128 --prompt "What is the meaning of life ?" 🎯 Deployment Summary: 📁 Files to copy: 2 (llama_main + libllama_runner.so) 🏗️ Extension module: Built-in (no separate .so needed) 🔧 Toolchain saved at: /home/sidart/working/executorch/arm-toolchain/arm-gnu-toolchain-14.3.rel1-x86_64-aarch64-none-linux-gnu 🔧 CMake toolchain file: /home/sidart/working/executorch/arm-toolchain-pi5.cmake Happy inferencing! 🚀
@pytorchbot cherry-pick --onto release/1.0 -c docs |
…ost machine (#15014) Test Plan: examples/raspberry_pi/rpi_setup.sh pi5 ... [100%] Linking CXX executable llama_main [100%] Built target llama_main [SUCCESS] LLaMA runner built successfully ==== Extracting Bundled Libraries ==== [INFO] Extracting GLIBC libraries from toolchain... [WARNING] Use bundled GLIBC script on RPI device ONLY if you encounter a GLIBC mismatch error when running llama_main. [SUCCESS] Bundled libraries prepared in: /home/sidart/working/executorch/cmake-out/bundled-libs [INFO] On Raspberry Pi, run: sudo ./install_libs.sh ==== Verifying Build Outputs ==== [INFO] Checking required binaries... [SUCCESS] ✓ llama_main (6.1M) [SUCCESS] ✓ libllama_runner.so (4.0M) [SUCCESS] ✓ libextension_module.a (89K) - static library [SUCCESS] All required binaries built successfully! ==== Setup Complete! ==== ✓ ExecuTorch cross-compilation setup completed successfully! 📦 Built binaries: • llama_main: /home/sidart/working/executorch/cmake-out/examples/models/llama/llama_main • libllama_runner.so: /home/sidart/working/executorch/cmake-out/examples/models/llama/runner/libllama_runner.so • libextension_module.a: Statically linked into llama_main ✅ • Bundled libraries: /home/sidart/working/executorch/cmake-out/bundled-libs/ 📋 Next steps: 1. Copy binaries to your Raspberry Pi pi5: scp /home/sidart/working/executorch/cmake-out/examples/models/llama/llama_main pi@<rpi-ip>:~/ scp /home/sidart/working/executorch/cmake-out/examples/models/llama/runner/libllama_runner.so pi@<rpi-ip>:~/ scp -r /home/sidart/working/executorch/cmake-out/bundled-libs/ pi@<rpi-ip>:~/ 2. Copy shared libraries to system location: sudo cp libllama_runner.so /lib/ # Only this one needed! sudo ldconfig 3. Dry run to check for GLIBC or other issues: ./llama_main --help # Ensure there are no GLIBC or other errors before proceeding. 4. If you see GLIBC errors, install bundled libraries: cd ~/bundled-libs && sudo ./install_libs.sh source setup_env.sh # Only do this if you encounter a GLIBC version mismatch or similar error. 5. Download your model and tokenizer: # Refer to the official documentation for exact details. 6. Run ExecuTorch with your model: ./llama_main --model_path ./model.pte --tokenizer_path ./tokenizer.model --seq_len 128 --prompt "What is the meaning of life ?" 🎯 Deployment Summary: 📁 Files to copy: 2 (llama_main + libllama_runner.so) 🏗️ Extension module: Built-in (no separate .so needed) 🔧 Toolchain saved at: /home/sidart/working/executorch/arm-toolchain/arm-gnu-toolchain-14.3.rel1-x86_64-aarch64-none-linux-gnu 🔧 CMake toolchain file: /home/sidart/working/executorch/arm-toolchain-pi5.cmake Happy inferencing! 🚀 ### Summary [PLEASE REMOVE] See [CONTRIBUTING.md's Pull Requests](https://github.com/pytorch/executorch/blob/main/CONTRIBUTING.md#pull-requests) for ExecuTorch PR guidelines. [PLEASE REMOVE] If this PR closes an issue, please add a `Fixes #<issue-id>` line. [PLEASE REMOVE] If this PR introduces a fix or feature that should be the upcoming release notes, please add a "Release notes: <area>" label. For a list of available release notes labels, check out [CONTRIBUTING.md's Pull Requests](https://github.com/pytorch/executorch/blob/main/CONTRIBUTING.md#pull-requests). ### Test plan [PLEASE REMOVE] How did you test this PR? Please write down any manual commands you used and note down tests that you have written if applicable. (cherry picked from commit a0e5280)
Cherry picking #15014The cherry pick PR is at #15151 The following tracker issues are updated: Details for Dev Infra teamRaised by workflow job |
Test Plan:
examples/raspberry_pi/rpi_setup.sh pi5
...
[100%] Linking CXX executable llama_main
[100%] Built target llama_main
[SUCCESS] LLaMA runner built successfully
==== Extracting Bundled Libraries ====
[INFO] Extracting GLIBC libraries from toolchain... [WARNING] Use bundled GLIBC script on RPI device ONLY if you encounter a GLIBC mismatch error when running llama_main. [SUCCESS] Bundled libraries prepared in: /home/sidart/working/executorch/cmake-out/bundled-libs [INFO] On Raspberry Pi, run: sudo ./install_libs.sh
==== Verifying Build Outputs ====
[INFO] Checking required binaries...
[SUCCESS] ✓ llama_main (6.1M)
[SUCCESS] ✓ libllama_runner.so (4.0M)
[SUCCESS] ✓ libextension_module.a (89K) - static library [SUCCESS] All required binaries built successfully!
==== Setup Complete! ====
✓ ExecuTorch cross-compilation setup completed successfully!
📦 Built binaries:
• llama_main: /home/sidart/working/executorch/cmake-out/examples/models/llama/llama_main
• libllama_runner.so: /home/sidart/working/executorch/cmake-out/examples/models/llama/runner/libllama_runner.so
• libextension_module.a: Statically linked into llama_main ✅
• Bundled libraries: /home/sidart/working/executorch/cmake-out/bundled-libs/
📋 Next steps:
Copy binaries to your Raspberry Pi pi5: scp /home/sidart/working/executorch/cmake-out/examples/models/llama/llama_main pi@:
/ scp /home/sidart/working/executorch/cmake-out/examples/models/llama/runner/libllama_runner.so pi@:/ scp -r /home/sidart/working/executorch/cmake-out/bundled-libs/ pi@:~/Copy shared libraries to system location: sudo cp libllama_runner.so /lib/ # Only this one needed! sudo ldconfig
Dry run to check for GLIBC or other issues: ./llama_main --help # Ensure there are no GLIBC or other errors before proceeding.
If you see GLIBC errors, install bundled libraries: cd ~/bundled-libs && sudo ./install_libs.sh source setup_env.sh # Only do this if you encounter a GLIBC version mismatch or similar error.
Download your model and tokenizer: # Refer to the official documentation for exact details.
Run ExecuTorch with your model: ./llama_main --model_path ./model.pte --tokenizer_path ./tokenizer.model --seq_len 128 --prompt "What is the meaning of life ?"
🎯 Deployment Summary:
📁 Files to copy: 2 (llama_main + libllama_runner.so)
🏗️ Extension module: Built-in (no separate .so needed)
🔧 Toolchain saved at: /home/sidart/working/executorch/arm-toolchain/arm-gnu-toolchain-14.3.rel1-x86_64-aarch64-none-linux-gnu
🔧 CMake toolchain file: /home/sidart/working/executorch/arm-toolchain-pi5.cmake
Happy inferencing! 🚀
Summary
[PLEASE REMOVE] See CONTRIBUTING.md's Pull Requests for ExecuTorch PR guidelines.
[PLEASE REMOVE] If this PR closes an issue, please add a
Fixes #<issue-id>
line.[PLEASE REMOVE] If this PR introduces a fix or feature that should be the upcoming release notes, please add a "Release notes: " label. For a list of available release notes labels, check out CONTRIBUTING.md's Pull Requests.
Test plan
[PLEASE REMOVE] How did you test this PR? Please write down any manual commands you used and note down tests that you have written if applicable.