{"id":21044980,"url":"https://github.com/quansight/torch-build","last_synced_at":"2025-11-08T06:03:52.960Z","repository":{"id":185584192,"uuid":"673764649","full_name":"Quansight/torch-build","owner":"Quansight","description":"Collection of scripts to build PyTorch and the domain libraries from source.","archived":false,"fork":false,"pushed_at":"2025-11-05T21:56:32.000Z","size":54,"stargazers_count":12,"open_issues_count":2,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-11-08T06:03:08.346Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Quansight.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-08-02T11:20:46.000Z","updated_at":"2025-11-05T21:56:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"77803c55-69e8-48a4-891e-be1dc9fc55b2","html_url":"https://github.com/Quansight/torch-build","commit_stats":null,"previous_names":["quansight/torch-build"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Quansight/torch-build","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quansight%2Ftorch-build","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quansight%2Ftorch-build/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quansight%2Ftorch-build/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quansight%2Ftorch-build/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Quansight","download_url":"https://codeload.github.com/Quansight/torch-build/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quansight%2Ftorch-build/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283307726,"owners_count":26814473,"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-08T02:00:06.281Z","response_time":57,"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":[],"created_at":"2024-11-19T14:19:24.607Z","updated_at":"2025-11-08T06:03:52.914Z","avatar_url":"https://github.com/Quansight.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Compiling PyTorch\n\n### Structure of a PyTorch build directory\n\nA PyTorch build directory contains five subdirectories:\n\n:- `pytorch/`\n- `torchbenchmark/`\n- `torch-audio/`\n- `torch-data/`\n- `torch-vision/`\n\nThere is also the directory containing this file, `torch-build/`, which can be anywhere\non your file system.\n\nBy default, the build directory is in `~/git` but there are two ways to build PyTorch in\nother directories:\n\n1. Setting the environment variable `PYTORCH_BUILD_SUFFIX` appends this value to the\n   build directory, and also to the Conda environment which is used. For example, if\n   `PYTORCH_BUILD_SUFFIX=-grad`, then the PyTorch build directory would be created\n   in `~/git-grad` and the Conda environment would be named `pytorch-dev`.\n\n2. Or for finer grained control, you can independently set the environment variable\n   `PYTORCH_BUILD_DIRECTORY` to set the build directory, `PYTORCH_CONDA_ENV` to set\n   the name of the Conda environment\n\nBy default, PyTorch is cloned from `git@github.com:pytorch/pytorch.git` but you can\noverride this by setting the environment variable `PYTORCH_GIT_USER`. For example, if\n`PYTORCH_GIT_USER=octacat` then the fork `git@github.com:octacat/pytorch.git`\nwill be used.\n\n### Setting up the environment\n\n- Set the correct CUDA version in `pytorch-dev.yaml` by changing the line `cuda-version=12.2`\n\n- Create the conda environment: `./torch-env.sh`\n\n- [If you don't have them] Install the Nvidia drivers from https://www.nvidia.com/download/index.aspx\n\n**Python version**. We set python=3.8 in `pytorch-dev.yaml`, as this is the minimum required version in PyTorch, and this disallows us from using features that are \"too new\".\nTo debug some issues that may not reproduce on Python 3.8, you may need to create a different env with a newer Python version.\n\n\n### Building PyTorch and due diligence\n\n- Have a read through the `pytorch-*` and `torch-*` scripts and edit them as needed.\n  - You will at least need to set `CUDA_PATH` and `TORCH_CUDA_ARCH_LIST` correctly in `torch-common.sh`.\n  - These scripts give you \"sane defaults\", but feel free to tailor them to your liking.\n- Running `torch-clone.sh` will download PyTorch and all the domain libraries. If you just want PyTorch, you can edit the script accordingly.\n- Running `pytorch-build.sh` will compile PyTorch.\n- Running `torch-build.sh` will compile PyTorch, the domain libs, and torchbench.\n- Running `torch-update.sh` checks out the last `main` in all the libraries. Useful if you haven't compiled in a while.\n\n\n# Running torchbench\n\nWithout making some of the following changes, benchmarks you run can be highly unstable, varying as much as 10% from run to run, even if you are running each benchmark multiple times. Note that you require root to be able to enact most of them.\n\n## GPU benchmarks\n\nTo run a torchbench model for CUDA devices on an A100 GPU, follow these steps:\n\n0. Set `export USE_FLASH_ATTENTION=1` and `export USE_MEM_EFF_ATTENTION=1` in `torch-common.py`\n2. Build pytorch and all the domain libraries with `torch-build.sh` (See above)\n3. Lock the GPU clock rates by running `sudo lock-clock-a100.sh`\n4. Launch the appropriate benchmark-runner with the relevant arguments, e.g.\n```\nPYTHONPATH=$HOME/git/torch-bench/ python benchmarks/dynamo/torchbench.py \\\n  --performance --inductor --train --amp --only hf_GPT2\n```\nIn the same directory there are also `huggingface.py` and `timm_models.py` which\nare run in a similar manner.\n\n## CPU benchmarks\n\nIf using an AWS instance (g4dn.metal), there is a script used by the Meta team for their benchmarks which is found in the `torchbench` repo. You can run it with the command\n\n```\nsudo $(which python) torchbenchmark/util/machine_config.py --configure\n```\n\nFor other machines, a similar result can be achieved manually by following these steps:\n\n1. Disable hyperthreading. Look at what the `set_hyper_threading` function in the `torchbenchmark/util/machine_config.py` does.\n2. Disable Turbo Boost. The CPU might not have it, if the directory `/sys/devices/system/cpu/intel_pstate` does not exist, no need to do anything. If it does exist, look at `set_intel_no_turbo_state` and `set_pstate_frequency` in `machine_config.py`.\n3. Set Intel c-state to 1. You need to edit `/etc/default/grub` and add `intel_idle.max_cstate=1` to the `GRUB_CMDLINE_LINUX_DEFAULT` variable. Then run `sudo update-grub` and reboot.\n3. CPU core isolation. This might not be strictly necessary if you can make sure there are no other processes running in the machine when running the benchmarks. The idea is to tell the OS not use some CPU cores at all unless they are specifically requested by `taskset`. Note that if you do this it will make all other workflows (such as compilation) slower since they will have less cores they can use.  To do this follow the same steps as in previous point but instead of `intel_idle.max_cstate=1` add `isolcpus=6-11` where `6-11` is the range of cores you want to isolate.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquansight%2Ftorch-build","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquansight%2Ftorch-build","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquansight%2Ftorch-build/lists"}