name: Setup Python & Install description: Sets up Python and installs project dependencies. inputs: python-version: description: 'Python version to use' required: false default: '3.12' key: description: 'Key for the python cache' required: false default: '' # if you don't set a key, it doesn't cache deps: description: 'Extra dependency groups (comma separated)' required: false default: '' pydeps: description: 'Extra Python dependency groups (space separated)' required: false default: '' opencl: description: "Install OpenCL?" required: false default: 'false' amd: description: "Install AMD?" required: false default: 'false' cuda: description: "Install CUDA?" required: false default: 'false' ocelot: description: "Install gpuocelot?" required: false default: 'false' webgpu: description: "Install webgpu?" required: false default: 'false' llvm: description: "Install LLVM?" required: false default: 'false' runs: using: "composite" steps: - name: Set up Python ${{ inputs.python-version }} id: setup-python uses: actions/setup-python@v5 with: python-version: ${{ inputs.python-version }} # **** Caching packages **** - name: Cache Python packages id: restore-venv uses: actions/cache@v4 with: path: ${{ github.workspace }}/.venv key: venv-${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-${{ inputs.deps }}-${{ inputs.pydeps }}-${{ hashFiles('**/setup.py') }}-${{ env.PYTHON_CACHE_VERSION }} # **** Caching downloads **** - name: Cache downloads (Linux) if: inputs.key != '' && runner.os == 'Linux' uses: actions/cache@v4 with: path: ~/.cache/tinygrad/downloads/ key: downloads-cache-${{ inputs.key }}-${{ env.DOWNLOAD_CACHE_VERSION }} - name: Cache downloads (macOS) if: inputs.key != '' && runner.os == 'macOS' uses: actions/cache@v4 with: path: ~/Library/Caches/tinygrad/downloads/ key: osx-downloads-cache-${{ inputs.key }}-${{ env.DOWNLOAD_CACHE_VERSION }} # **** Python deps **** - name: Install dependencies in venv (with extra) if: inputs.deps != '' && steps.restore-venv.outputs.cache-hit != 'true' shell: bash run: | python -m venv .venv if [[ "$RUNNER_OS" == "Windows" ]]; then source .venv/Scripts/activate else . .venv/bin/activate fi python -m pip install -e ".[${{ inputs.deps }}]" ${{ inputs.pydeps }} --extra-index-url https://download.pytorch.org/whl/cpu --extra-index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/Triton-Nightly/pypi/simple/ - name: Install dependencies in venv (without extra) if: inputs.deps == '' && steps.restore-venv.outputs.cache-hit != 'true' shell: bash run: | python -m venv .venv if [[ "$RUNNER_OS" == "Windows" ]]; then source .venv/Scripts/activate else . .venv/bin/activate fi python -m pip install -e . ${{ inputs.pydeps }} - name: Set up venv environment shell: bash run: | echo "VIRTUAL_ENV=${{ github.workspace }}/.venv" >> "$GITHUB_ENV" echo "OMP_NUM_THREADS=1" >> "$GITHUB_ENV" # no buffers should be over 300MB in CI echo "MAX_BUFFER_SIZE=300000000" >> "$GITHUB_ENV" if [[ "$RUNNER_OS" == "Windows" ]]; then echo "${{ github.workspace }}/.venv/Scripts" >> "$GITHUB_PATH" else echo "${{ github.workspace }}/.venv/bin" >> "$GITHUB_PATH" fi # ******************* apt ******************* - name: Add OpenCL Repo if: inputs.opencl == 'true' && runner.os == 'Linux' shell: bash run: echo "deb [ allow-insecure=yes ] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list - name: Add AMD Repo (Linux) if: inputs.amd == 'true' && runner.os == 'Linux' shell: bash run: | wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | gpg --dearmor | sudo tee /etc/apt/keyrings/rocm.gpg > /dev/null sudo tee /etc/apt/sources.list.d/rocm.list <