Skip to content

Conversation

psiddh
Copy link
Contributor

@psiddh psiddh commented Oct 10, 2025

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@:/ 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@:~/

  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 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.

Copy link

pytorch-bot bot commented Oct 10, 2025

🔗 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 Failure

As of commit a42b3a8 with merge base 45336ce (image):

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.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 10, 2025
@psiddh psiddh requested a review from digantdesai October 10, 2025 20:06
Copy link

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@psiddh psiddh changed the title Summary: RaspberryPi Tutorial to deply & infer llama models (Rpi4 & R… Summary: Add the Cross compilation Script for RPi (4 & 5) for Linux host machine Oct 10, 2025
parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
pi4|pi5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not others?

Copy link
Contributor Author

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

Comment on lines 122 to 123
--bundled-glibc Bundle toolchain GLIBC libraries (default)
--no-bundled-glibc Use system GLIBC (requires RPi GLIBC upgrade)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--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)

Copy link
Contributor Author

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.

pi4|pi5 Target Raspberry Pi model

Options:
--bundled-glibc Bundle toolchain GLIBC libraries (default)
Copy link
Contributor

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?

Copy link
Contributor Author

@psiddh psiddh Oct 14, 2025

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,

Comment on lines 124 to 125
--force-rebuild Force complete rebuild of all components
--force-download Force re-download of the ARM toolchain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--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
Copy link
Contributor

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

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"
Copy link
Contributor

@digantdesai digantdesai Oct 13, 2025

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

cd "$TOOLCHAIN_DIR"

# Download toolchain
if ! curl -L -o "$toolchain_archive" "$toolchain_url"; then
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

arch_flags="-march=armv8-a -mtune=cortex-a72"
;;
pi5)
arch_flags="-march=armv8.2-a+dotprod+fp16"
Copy link
Contributor

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?

Copy link
Contributor Author

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)

Comment on lines 512 to 513
cp "$toolchain_lib_dir"/libc.so.* "$bundle_dir/" 2>/dev/null || true
cp "$toolchain_lib_dir"/libm.so.* "$bundle_dir/" 2>/dev/null || true
Copy link
Contributor

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

Copy link
Contributor Author

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


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'
Copy link
Contributor

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?

Copy link
Contributor Author

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

Comment on lines 598 to 603
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
Copy link
Contributor

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?

Copy link
Contributor Author

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

echo " • libllama_runner.so: $CMAKE_OUT_DIR/examples/models/llama/runner/libllama_runner.so"

# Smart extension module reporting
if [[ "$EXTENSION_STATIC_LINKED" == "true" ]]; then
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

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>:~/"
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

fi

echo -e "\n2. Copy shared libraries to system location:"
echo " sudo cp libllama_runner.so /lib/ # Only this one needed!"
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# Create environment setup script
cat > "$SCRIPT_DIR/setup_env.sh" << 'ENVEOF'
#!/bin/bash
export LD_LIBRARY_PATH="/usr/local/lib/executorch:$LD_LIBRARY_PATH"
Copy link
Contributor

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

Copy link
Contributor

@digantdesai digantdesai left a 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! 🚀
@psiddh psiddh merged commit a0e5280 into pytorch:main Oct 15, 2025
130 of 138 checks passed
@psiddh
Copy link
Contributor Author

psiddh commented Oct 15, 2025

@pytorchbot cherry-pick --onto release/1.0 -c docs

pytorchbot pushed a commit that referenced this pull request Oct 15, 2025
…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)
@pytorchbot
Copy link
Collaborator

Cherry picking #15014

The cherry pick PR is at #15151 The following tracker issues are updated:

Details for Dev Infra team Raised by workflow job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants