{"id":13398600,"url":"https://github.com/pytorch/glow","last_synced_at":"2025-05-14T12:12:43.068Z","repository":{"id":37548250,"uuid":"105281531","full_name":"pytorch/glow","owner":"pytorch","description":"Compiler for Neural Network hardware accelerators","archived":false,"fork":false,"pushed_at":"2024-05-11T13:35:10.000Z","size":77819,"stargazers_count":3279,"open_issues_count":435,"forks_count":699,"subscribers_count":153,"default_branch":"master","last_synced_at":"2025-04-11T04:59:17.907Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pytorch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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}},"created_at":"2017-09-29T14:28:18.000Z","updated_at":"2025-04-09T14:06:28.000Z","dependencies_parsed_at":"2024-11-20T05:05:52.698Z","dependency_job_id":null,"html_url":"https://github.com/pytorch/glow","commit_stats":{"total_commits":6624,"total_committers":386,"mean_commits":17.16062176165803,"dds":0.8571859903381642,"last_synced_commit":"05dd99b971dc5eeeb2b86a80c74dca800653d548"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytorch%2Fglow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytorch%2Fglow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytorch%2Fglow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytorch%2Fglow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pytorch","download_url":"https://codeload.github.com/pytorch/glow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345273,"owners_count":21088244,"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","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-07-30T19:00:29.106Z","updated_at":"2025-04-11T04:59:40.503Z","avatar_url":"https://github.com/pytorch.png","language":"C++","readme":"![Glow Logo](./docs/logo.svg)\n\n[![pytorch](https://circleci.com/gh/pytorch/glow.svg?style=shield)](https://circleci.com/gh/pytorch/glow)\n\n\nGlow is a machine learning compiler and execution engine for hardware\naccelerators.  It is designed to be used as a backend for high-level machine\nlearning frameworks.  The compiler is designed to allow state of the art\ncompiler optimizations and code generation of neural network graphs. This\nlibrary is in active development. The project plan is described in the Github\nissues section and in the\n[Roadmap](https://github.com/pytorch/glow/wiki/Glow-Roadmap) wiki page.\n\n## Partners\n\nContributions to Glow are welcomed and encouraged! Glow is developed in\ncollaboration with the following partners:\n\n\n\u003c!---\nNote:\nList of partner logos sorted alphabetically column order.\n--\u003e\n\n| ![Bitmain Logo](./docs/partners/bitmain.png) | ![Habana Logo](./docs/partners/habana.png) | ![ST Logo](./docs/partners/st.png)  |\n:-------------------------:|:-------------------------:|:-------------------------:\n| ![Cadence Logo](./docs/partners/cadence.png) | ![Intel Logo](./docs/partners/intel.png) | ![Synopsys Logo](./docs/partners/synopsys.png) |\n| ![CEVA Logo](./docs/partners/ceva.png)   |  ![Marvell Logo](./docs/partners/marvell.png) |  |\n| ![Esperanto Logo](./docs/partners/esperanto.png)  | ![NXP Logo](./docs/partners/nxp.png) |  |\n\n\n## How does it work?\n\nGlow lowers a traditional neural network dataflow graph into a two-phase\nstrongly-typed [intermediate representation (IR)](./docs/IR.md). The high-level\nIR allows the optimizer to perform domain-specific optimizations. The\nlower-level instruction-based address-only IR allows the compiler to perform\nmemory-related optimizations, such as instruction scheduling, static memory\nallocation and copy elimination. At the lowest level, the optimizer performs\nmachine-specific code generation to take advantage of specialized hardware\nfeatures. Glow features a lowering phase which enables the compiler to support a\nhigh number of input operators as well as a large number of hardware targets by\neliminating the need to implement all operators on all targets. The lowering\nphase is designed to reduce the input space and allow new hardware backends to\nfocus on a small number of linear algebra primitives.\nThe design philosophy is described in an [arXiv paper](https://arxiv.org/abs/1805.00907).\n\n![](./docs/3LevelIR.png)\n\n## Getting Started\n\n### System Requirements\n\nGlow builds and runs on macOS and Linux. The software depends on a modern C++\ncompiler that supports C++11, on CMake, LLVM (\u003e=7.0), glog, protocol buffers, and\nlibpng.\n\n#### Get Glow!\n\n  ```bash\n  git clone git@github.com:pytorch/glow.git  # or: git clone https://github.com/pytorch/glow.git\n  cd glow\n  ```\n\n#### Submodules\n\nGlow depends on a few submodules: googletest, onnx, and a library\nfor FP16 conversions.\n\nTo get them, from the glow directory, run:\n\n  ```bash\n  git submodule update --init --recursive\n  ```\n\n#### Source dependencies\n\nGlow depends on `fmt`, which must be built from source:\n```bash\ngit clone https://github.com/fmtlib/fmt\nmkdir fmt/build\ncd fmt/build\ncmake ..\nmake\nsudo make install\n```\n\n#### macOS\n\nInstall the required dependencies using either [Homebrew](https://brew.sh/) or\n[MacPorts](https://www.macports.org/). If using Homebrew, run:\n\n  ```bash\n  brew install cmake graphviz libpng ninja protobuf wget glog autopep8 llvm   \\\n      boost double-conversion gflags jemalloc libevent lz4 openssl pkg-config \\\n      snappy xz\n  ```\n\nIf using MacPorts, run:\n\n  ```bash\n  port install cmake graphviz libpng ninja protobuf-cpp wget google-glog \\\n      boost double-conversion gflags jemalloc libevent lz4 openssl snappy xz\n  # Choose version \u003e= 7\n  export LLVM_VERSION=7\n  port install llvm-$LLVM_VERSION.0 \n  ```\n\n\nNote that LLVM is installed in a non-default location to avoid conflicts with\nthe system's LLVM --Homebrew usually installs LLVM in `/usr/local/opt/llvm/`,\nwhereas MacPorts installs it in `/opt/local/libexec/llvm-$LLVM_VERSION.0/`. This means that\nCMake will need to be told where to find LLVM when building; instructions on\nthat can be found [here](#building-with-dependencies-llvm).\n\nFinally, create a symbolic link to the Homebrew- or MacPorts-installed\n`clang-*` tools so that the `utils/format.sh` script is able to find them later\non. For a Homebrew-managed installation, run:\n  ```\n  ln -s \"/usr/local/opt/llvm/bin/clang-format\" \"/usr/local/bin/clang-format\"\n  ln -s \"/usr/local/opt/llvm/bin/clang-tidy\" \"/usr/local/bin/clang-tidy\"\n  ```\nFor MacPorts, run:\n  ```\n  ln -s \"/opt/local/libexec/llvm-$LLVM_VERSION.0/bin/clang-format\" \"/usr/local/bin/clang-format\"\n  ln -s \"/opt/local/libexec/llvm-$LLVM_VERSION.0/bin/clang-tidy\" \"/usr/local/bin/clang-tidy\"\n```\n\n\u003e **Note:** Starting with macOS Mojave, Xcode's command line tools changed header layout. \n\u003e In order for Glow to build on Mojave, you might need to install\n\u003e `macOS_SDK_headers_for_macOS_10.14.pkg`, located in \n\u003e `/Library/Developer/CommandLineTools/Packages/`.\n\u003e For macOS Catalina you might need to explicitly specify SDKROOT: \n\u003e `export SDKROOT=\"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk\"`\n\n\n#### Ubuntu\n\n[The following instructions have been tested on Ubuntu 16.04 and 18.04]\n\nIn order to build Glow on Ubuntu it is necessary to install a few packages. The\nfollowing command should install the required dependencies:\n\n  ```bash\n  sudo apt-get install clang clang-8 cmake graphviz libpng-dev \\\n      libprotobuf-dev llvm-8 llvm-8-dev ninja-build protobuf-compiler wget \\\n      opencl-headers libgoogle-glog-dev libboost-all-dev \\\n      libdouble-conversion-dev libevent-dev libssl-dev libgflags-dev \\\n      libjemalloc-dev libpthread-stubs0-dev liblz4-dev libzstd-dev libbz2-dev \\\n      libsodium-dev libfmt-dev\n  ```\n\n[Note: Ubuntu 16.04 and 18.04 ship with llvm-6 and need to be upgraded before building Glow. Building Glow on Ubuntu 16.04 with llvm-7 fails because llvm-7 xenial distribution uses an older c++ ABI, however building Glow on Ubuntu 18.04 with llvm-7 has been tested and is successful]\n\nIt may be desirable to use `update-alternatives` to manage the version of\nclang/clang++:\n\n  ```bash\n  sudo update-alternatives --install /usr/bin/clang clang \\\n      /usr/lib/llvm-8/bin/clang 50\n  sudo update-alternatives --install /usr/bin/clang++ clang++ \\\n      /usr/lib/llvm-8/bin/clang++ 50\n  ```\n\nGlow uses the system default C/C++ compiler (/usr/bin/c++), and so you may also\nwant to switch your default C/C++ compiler to clang:\n\n  ```bash\n  sudo update-alternatives --config cc\n      # Select the option corresponding to /usr/bin/clang ...\n  sudo update-alternatives --config c++\n      # Select the option corresponding to /usr/bin/clang++ ...\n  ```\n\nGlow *should* build just fine with gcc (e.g. gcc 5.4), but we mostly use clang\nand are more attentive to compatibility with clang.\n\nFinally, in order to support the ONNX net serialization format, Glow requires\n`protobuf \u003e= 2.6.1`, but the above command may install older\nversion on older Ubuntu (e.g. 14.04). If this is the case, we suggest to look\nat `utils/install_protobuf.sh` to install a newer version from source.\n\nFor details on installing OpenCL on Ubuntu please see\n[these instructions](docs/Building.md#opencl-on-ubuntu).\n\n### Configure and Build\n\nTo build the compiler, create a build directory and run cmake on the source\ndirectory. It's a good idea to build two configurations (Release and Debug)\nbecause some programs take a really long time to run in Debug mode. It's also a\ngood idea to build the project outside of the source directory.\n\n  ```bash\n  mkdir build_Debug\n  cd build_Debug\n  cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../glow\n  ninja all\n  ```\n\nIt's possible to configure and build the compiler with any CMake generator,\nlike GNU Makefiles, Ninja and Xcode build.\n\nFor platform-specific build instructions and advanced options, such as\nbuilding with Address-Sanitizers refer to this guide:\n[Building the Compiler](docs/Building.md).\n\nIf you're running macOS v10.14 (Mojave) and `ninja all` fails because it can't\nfind headers (e.g. `string.h`), run this command to fix it, and try again.\nMore information is available [here](https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes)\nunder \"Command Line Tools\".\n\n  ```bash\n  open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg\n  ```\n\nFor macOS v10.15 (Catalina) you might need to explicitly specify SDKROOT:\n\n   ```bash\n   export SDKROOT=\"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk\"\n   ```\n\n\n#### Building with dependencies (LLVM)\n\nBy default, Glow will use a system provided LLVM.  Note that Glow requires LLVM\n7.0 or later. If you have LLVM installed in a non-default location (for\nexample, if you installed it using Homebrew on macOS), you need to tell CMake\nwhere to find llvm using `-DLLVM_DIR`. For example, if LLVM were\ninstalled in `/usr/local/opt`:\n\n  ```bash\n  cmake -G Ninja ../glow \\\n      -DCMAKE_BUILD_TYPE=Debug \\\n      -DLLVM_DIR=/usr/local/opt/llvm/lib/cmake/llvm\n  ```\n\nIf LLVM is not available on your system you'll need to build it manually.  Run\nthe script '`/utils/build_llvm.sh` to clone, build and install LLVM in a local\ndirectory. You will need to configure Glow with the flag `-DLLVM_DIR` to tell\nthe build system where to find LLVM given the local directory you installed it\nin (e.g. `-DLLVM_DIR=/path/to/llvm_install/lib/cmake/llvm` if using\n`build_llvm.sh`).\n\n## Testing and Running\n\n### Unit tests\n\nThe project has a few unit tests in the tests/unittests subdirectory. To run all\nof them, simply run `ninja test`.\n\n### C++ API examples\n\nA few test programs that use Glow's C++ API are found under the `examples/`\nsubdirectory. The `mnist`, `cifar10`, `fr2en` and `ptb` programs train and run digit\nrecognition, image classification and language modeling benchmarks,\nrespectively.\n\nTo run these programs, build Glow in Release mode, then run the following commands\nto download the cifar10, mnist and ptb databases.\n\n  ```bash\n  python ../glow/utils/download_datasets_and_models.py --all-datasets\n  ```\n\nNow run the examples. Note that the databases should be in the current working\ndirectory.\n\n  ```bash\n  ./bin/mnist\n  ./bin/cifar10\n  ./bin/fr2en\n  ./bin/ptb\n  ./bin/char-rnn\n  ```\n\nIf everything goes well you should see:\n  * `mnist`: pictures from the mnist digits database\n  * `cifar10`: image classifications that steadily improve\n  * `fr2en`: an interactive French-to-English translator\n  * `ptb`: decreasing perplexity on the dataset as the network trains\n  * `char-rnn`: generates random text based on some document\n\nNote that the default build mode is `Debug`, which means that the compiler\nitself is easy to debug because the binary contains debug info, lots of\nassertions, and the optimizations are disabled. It also means that the compiler\nand runtime are very slow, and the execution time can be hundreds of times\nslower than that of release builds. If you wish to benchmark the compiler, run\nlong benchmarks, or release the product then you should compile the compiler in\nRelease mode. Check the main CMake file for more details.\n\nMore details on testing and running Glow can be found in:\n[Testing the Glow Compiler](docs/Testing.md).\n\n### Ahead-of-time Compilation\n\nGlow can be used to compile neural networks into object files containing native\ncode.  We provide resnet50 (both quantized and non-quantized versions) as an\nexample of this capability in `examples/bundles/resnet50`.  See [Creating\nStandalone Executable Bundles](docs/AOT.md) for more detail.\n\n## Contributing\n\nTo get started contributing, please refer to the following guides:\n* [Contributing](CONTRIBUTING.md)\n* [Coding Standards](docs/CodingStandards.md)\n* [Code of Conduct](CODE_OF_CONDUCT.md)\n\n### Communication\n\n* Forums: discuss implementations, research, etc: https://discuss.pytorch.org/c/glow.\n  Make sure to label topic with the [\"glow\"](https://discuss.pytorch.org/c/glow) category.\n* GitHub issues: bug reports, feature requests, install issues, RFCs, thoughts, etc.\n\n## License\n\nGlow is licensed under the [Apache 2.0 License](LICENSE).\n","funding_links":[],"categories":["C++","Compilers","Open Source Projects","Tools","Deep Learning Framework","PROJECTS","PyTorch Tools, Libraries, and Frameworks","\u003ca id=\"1d9dec1320a5d774dc8e0e7604edfcd3\"\u003e\u003c/a\u003e工具-新添加的","Reinforcement Learning"],"sub_categories":["Graph Compiler","High-Level DL APIs","2023","\u003ca id=\"8f1b9c5c2737493524809684b934d49a\"\u003e\u003c/a\u003e文章\u0026\u0026视频","Inverse Reinforcement Learning","Hard-ware Integration"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpytorch%2Fglow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpytorch%2Fglow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpytorch%2Fglow/lists"}