{"id":33596412,"url":"https://github.com/wzqvip/jetson-pytorch-builder","last_synced_at":"2025-12-01T18:02:37.135Z","repository":{"id":326043932,"uuid":"1103610047","full_name":"wzqvip/jetson-pytorch-builder","owner":"wzqvip","description":"build PyTorch with CUDA for Jetson Orin and Thor.","archived":false,"fork":false,"pushed_at":"2025-11-28T01:01:57.000Z","size":30,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-28T14:13:53.028Z","etag":null,"topics":["cuda","jetson","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wzqvip.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-25T05:15:07.000Z","updated_at":"2025-11-28T11:25:37.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/wzqvip/jetson-pytorch-builder","commit_stats":null,"previous_names":["wzqvip/jetson-pytorch-builder"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/wzqvip/jetson-pytorch-builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wzqvip%2Fjetson-pytorch-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wzqvip%2Fjetson-pytorch-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wzqvip%2Fjetson-pytorch-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wzqvip%2Fjetson-pytorch-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wzqvip","download_url":"https://codeload.github.com/wzqvip/jetson-pytorch-builder/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wzqvip%2Fjetson-pytorch-builder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27368921,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-29T02:00:06.589Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cuda","jetson","pytorch"],"created_at":"2025-11-29T23:03:22.166Z","updated_at":"2025-12-01T18:02:37.129Z","avatar_url":"https://github.com/wzqvip.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyTorch from Source on Jetson Orin \u0026 Thor\n\nThis workspace automates building stock [PyTorch](https://github.com/pytorch/pytorch#from-source) with CUDA enabled for Python 3.8–3.12 on both Jetson Orin (Ampere, JetPack 6.x) and Jetson AGX Thor (Blackwell, JetPack 7.x). It codifies the upstream PyTorch instructions and the NVIDIA Developer Forum guidance for [Orin builds](https://forums.developer.nvidia.com/t/native-build-of-pytorch-for-jetson/71842) and [Thor/JetPack 7 builds](https://forums.developer.nvidia.com/t/pytorch-2-4-build-jetson-orin/291219). NVIDIA 官方 pip 仓库只提供少量预编译版本，这里可以自编译带 CUDA 的版本以匹配需求。\n\n## Prerequisites\n\n- JetPack 6.x (Orin) or JetPack 7.x (Thor) with CUDA `/usr/local/cuda` and cuDNN already installed.\n- At least 32 GB of free disk (more if you plan to keep all 3 wheels at once) and large swap (builds routinely spill \u003e16 GB RAM).\n- System packages:\n\n  ```bash\n  sudo apt update\n  sudo apt install -y build-essential git cmake ninja-build \\\n      libopenblas-dev libopenmpi-dev openmpi-bin libatlas-base-dev libprotobuf-dev \\\n      protobuf-compiler libssl-dev zlib1g-dev libffi-dev\n  ```\n- `~/miniconda3` (already present on this machine) or any conda distribution. The scripts will create isolated envs per Python version.\n\nThor-specific sanity checks (taken from this devkit, JetPack 7.0 / Ubuntu 24.04):\n\n```bash\nuname -a\n# Linux thor-taco 6.8.12-tegra ... aarch64 GNU/Linux\ncat /etc/nv_tegra_release\n# R38.2.2 ... BOARD: generic (AGX Thor)\nnvidia-smi --query-gpu=name,compute_cap,driver_version,cuda_version --format=csv\n# NVIDIA Thor, 11.0, 580.00, 13.0\n```\n\nThe `build.sh` script auto-detects the compute capability (`TORCH_CUDA_ARCH_LIST`) via `nvidia-smi` when present, falling back to `/proc/device-tree/model`. On this Thor devkit it resolves to `11.0`; on Orin it defaults to `8.7`.\n\n\u003e ℹ️ Jetson builds cannot currently use NVIDIA's binary NCCL. Following the forum advice above, the scripts default to `USE_NCCL=0`, `USE_DISTRIBUTED=0`, `USE_MKLDNN=0`, and `USE_NNPACK=0`. Override them if you have working alternatives.\n\n## Layout\n\n- `build.sh` — clones PyTorch (once), prepares the requested Python env, and runs `python setup.py bdist_wheel` with Jetson-friendly defaults (auto-detected CUDA arch, NCCL disabled unless you opt in, etc.).\n- `build-all.sh` — convenience wrapper that invokes `build.sh` for 3.10, 3.11, and 3.12 (or any list of versions you pass).\n- `src/` — source tree managed by the scripts (`src/pytorch` is the git checkout).\n- `logs/` — timestamped build logs per Python version.\n- `wheels/` — collected `.whl` artefacts per Python version (`wheels/py310`, `wheels/py311`, ...).\n\n## Quick start\n\n```bash\ncd ~/jetson-pytorch-builder\nchmod +x build.sh build-all.sh\n# Build all supported versions (3.8–3.12)\n./build-all.sh\n# OR build one at a time\n#    ^ Python version  ^ optional PyTorch git ref/tag\n./build.sh 3.11 v2.4.1\n```\n\nEach run:\n\n1. Creates/updates `src/pytorch` (defaults to upstream tag `v2.4.0`, override with `PYTORCH_BRANCH=\u003ctag\u003e` or pass a second argument such as `./build.sh 3.12 main`).\n2. Creates a matching conda env (`torch-py310`, `torch-py311`, `torch-py312`) if it does not exist yet.\n3. Installs PyTorch's Python build requirements into the env.\n4. Cleans the repo tree (`git clean -fdx`) to avoid cross-version contamination.\n5. Compiles PyTorch with CUDA enabled, targeting the detected GPU (`TORCH_CUDA_ARCH_LIST` auto-detects to 8.7 for Orin, 11.0 for Thor; override via env var to cross-compile).\n6. Copies the newest `torch-*.whl` into `wheels/pyNNN`.\n\nSuccessful builds print the wheel path at the end and log everything to `logs/pytorch-py\u003cversion\u003e-\u003ctimestamp\u003e.log`.\n\n## Current Support\n\n* ###  Jetson Orin\n\n  * [ ] Python 3.8\n  * [ ] Python 3.9\n  * [ ] Python 3.10\n  * [ ] Python 3.11\n  * [ ] Python 3.12\n* ###  Jetson Thor\n\n  * [ ] Python 3.8\n  * [ ] Python 3.9\n  * [ ] Python 3.10\n  * [X] Python 3.11\n  * [ ] Python 3.12\n\n## Customisation\n\nAll relevant knobs can be changed through environment variables:\n\n| Variable | Default | Meaning |\n| --- | --- | --- |\n| `PYTORCH_BRANCH` | `v2.4.0` | Upstream tag/branch to checkout (can also pass as the second argument to `build.sh`). |\n| `PYTORCH_REPO` | `https://github.com/pytorch/pytorch.git` | Clone source. |\n| `TORCH_CUDA_ARCH_LIST` | auto (`11.0` on Thor, `8.7` on Orin) | Target GPU architectures. Override to cross-compile. |\n| `MAX_JOBS` | `$(nproc)` | Parallel compilation jobs. Tune to control RAM usage. |\n| `CUDA_HOME` | `/usr/local/cuda` | CUDA root. |\n| `USE_NCCL`, `USE_DISTRIBUTED`, `USE_MKLDNN`, `USE_NNPACK`, `USE_QNNPACK` | Jetson defaults set in `build.sh`. |\n| `TORCH_VERSION_OVERRIDE` | auto from tag (e.g., `v2.4.0` → `2.4.0`) | Forces `TORCH_BUILD_VERSION` so the wheel filename/metadata advertises your custom build. Set empty to keep upstream git-style versions or to supply your own (e.g., `2.4.0-jetson.1`). |\n| `TORCH_BUILD_NUMBER_OVERRIDE` | `1` | Optional build number passed along when `TORCH_VERSION_OVERRIDE` is set. |\n\nExample:\n\n```bash\nTORCH_CUDA_ARCH_LIST=\"8.7;8.9\" USE_NCCL=1 MAX_JOBS=8 ./build.sh 3.12\n```\n\n## Installing the wheels\n\nOnce a build finishes, install it inside any target environment (conda, system Python, etc.):\n\n```bash\npip install ~/jetson-pytorch-builder/wheels/py312/torch-*.whl\n```\n\nCopy the wheel to other Jetson nodes as needed. Keep the logs handy for support/bug reports.\n\n### Versioning and torchvision / torchaudio compatibility\n\nBy default PyTorch's build system emits versions like `2.4.0a0+git\u003csha\u003e`. This repo now **auto-sets `TORCH_BUILD_VERSION` to the numeric part of your tag** (e.g., `v2.4.0` → `2.4.0`), so the wheel name/metadata matches what torchvision/torchaudio expect. For non-tag refs (e.g., `main`), no override is applied unless you set it explicitly.\n\nTwo ways to stay sane:\n\n1. **Set an explicit version for your wheel.**\n\n   ```bash\n   TORCH_VERSION_OVERRIDE=\"2.4.0-jetson.1\" ./build.sh 3.11 v2.4.0\n   ```\n\n   The resulting wheel becomes `torch-2.4.0-jetson.1-...whl`, making it easy to match dependencies.\n\n2. **Install torchvision without re-resolving torch.**\n\n   If you keep the default `2.4.0a0+git...` version, install the matching source release and skip dependency checks:\n\n   ```bash\n   pip install torchvision==0.19.0 --no-deps\n   pip install torchaudio==2.4.0 --no-deps   # adjust to the PyTorch series you built\n   ```\n\n   This mirrors the PyTorch instructions for source builds where `torch` is already present.\n\n## Thor (Blackwell / JetPack 7) notes\n\n- JetPack 7 ships CUDA 13.0 and driver 580; make sure host packages and `CUDA_HOME` point to `/usr/local/cuda-13.0` (symlinked by default). The script logs the resolved path for traceability.\n- Blackwell support in PyTorch is still evolving; stick to PyTorch v2.4+ (default `v2.4.0`) or nightly master for proper `sm_110` kernels. You can change `PYTORCH_BRANCH` to `main` when you need bleeding-edge fixes.\n- NCCL is still unavailable on Jetson, so distributed training remains disabled.\n- If you parallelize with `MAX_JOBS \u003e 8`, ensure Thor's LPDDR memory controller has enough headroom or the build may thrash swap.\n\n## Troubleshooting notes\n\n- Add swap with `sudo fallocate -l 32G /swapfile \u0026\u0026 sudo mkswap /swapfile ...` if the compiler OOMs.\n- Ensure `nvcc --version` matches your JetPack CUDA (`nvcc --version` should report 13.0 on Thor, 12.x on Orin). If not, export `CUDA_HOME` explicitly.\n- `python setup.py clean` is implicitly handled by `git clean -fdx`; remove `build/` manually if you pause/resume by hand.\n- Refer to the PyTorch source build doc and NVIDIA forum threads listed at the top for more edge-case fixes (e.g., building with TensorRT, CUTLASS tuning, FlashAttention patches, etc.).\n\nHappy compiling!\n\nSpecial notes: The complete repo is written by Codex GPT-5.1 medium. I do not garentee this will work on your machine. Merge requests welcomed.\nTested on:\nJetson Thor: Linux thor-taco 6.8.12-tegra #1 SMP PREEMPT Thu Sep 25 15:19:42 PDT 2025 aarch64 aarch64 aarch64 GNU/Linux\n  Soc: tegra264\n  CUDA Arch BIN: 13.0\n  L4T: 38.2.2\n  Jetpack: 7.0\n  CUDA: 13.0.48\n  cuDNN: 9.12.0\n  TensorRT: 10.13.3.9\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwzqvip%2Fjetson-pytorch-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwzqvip%2Fjetson-pytorch-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwzqvip%2Fjetson-pytorch-builder/lists"}