Skip to content

Commit

Permalink
python setup
Browse files Browse the repository at this point in the history
torch-mlir pip dep

buildifier

use python 3.10 llvm/llvm-project#75963

fix

fixes

--test_output=errors for showing errors on GHA

cleanup

minor

add py_test

fix

fix paths

fix

add python tests to test_suite

headers

enable python lit tests

buildifier

clean disk space

fix

bump actions versions

fix

fix

fix

update requirements

minor

try stablehlo without test_output

cleanup

specify shell

disk space cleanup

trial

fix

more fixes

fix

fix
  • Loading branch information
sjain-stanford committed Feb 11, 2024
1 parent b0d474e commit 11f3e27
Show file tree
Hide file tree
Showing 30 changed files with 514 additions and 93 deletions.
64 changes: 64 additions & 0 deletions .github/actions/setup-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Also available under a BSD-style license. See LICENSE.

name: "Setup build environment"
description: "Setup build environment"

inputs:
cache-prefix:
required: true
default: 'mlir-tcp'

runs:
# This is a composite action - has a list of steps to execute.
using: "composite"

steps:
# https://github.com/jlumbroso/free-disk-space/blob/main/action.yml
- name: Free disk space
shell: bash
run: |
df -h
sudo swapoff -a
sudo rm -f /swapfile
sudo rm -f /mnt/swapfile
free -h
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo apt-get remove -y '^aspnetcore-.*' || echo "::warning::The command [sudo apt-get remove -y '^aspnetcore-.*'] failed to complete successfully. Proceeding..."
sudo apt-get remove -y '^dotnet-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^dotnet-.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y '^llvm-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^llvm-.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y 'php.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y 'php.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y '^mongodb-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^mongodb-.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y '^mysql-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^mysql-.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri --fix-missing || echo "::warning::The command [sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y google-cloud-sdk --fix-missing || echo "::debug::The command [sudo apt-get remove -y google-cloud-sdk --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y google-cloud-cli --fix-missing || echo "::debug::The command [sudo apt-get remove -y google-cloud-cli --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get autoremove -y || echo "::warning::The command [sudo apt-get autoremove -y] failed to complete successfully. Proceeding..."
sudo apt-get clean || echo "::warning::The command [sudo apt-get clean] failed to complete successfully. Proceeding..."
docker rmi $(docker image ls -aq)
sudo docker image prune --all --force || true
df -h
# Continually update cache even if there's a "hit" during
# restore to avoid the cache going stale over time
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
- name: Setup cache for bazel
uses: actions/cache@v4
with:
path: ~/.cache/bazel
key: ${{ inputs.cache-prefix }}-bazel-build-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
${{ inputs.cache-prefix }}-bazel-build-cache-${{ runner.os }}
- name: Create bazel cache dir when not found
shell: bash
run: |
if [ ! -d "${HOME}/.cache/bazel" ]; then
mkdir -p "${HOME}/.cache/bazel"
fi
22 changes: 5 additions & 17 deletions .github/workflows/bazelBuildAndTestLlvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,12 @@ jobs:

steps:
- name: Checkout mlir-tcp
uses: actions/checkout@v3
uses: actions/checkout@v4

# Continually update cache even if there's a "hit" during
# restore to avoid the cache going stale over time
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
- name: Setup cache for bazel
uses: actions/cache@v3
- name: Setup workspace
uses: ./.github/actions/setup-build
with:
path: ~/.cache/bazel
key: llvm-project-bazel-build-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
llvm-project-bazel-build-cache-${{ runner.os }}
- name: Create bazel cache dir when not found
run: |
if [ ! -d "${HOME}/.cache/bazel" ]; then
mkdir -p "${HOME}/.cache/bazel"
fi
cache-prefix: 'llvm-project'

- name: Build docker image
run: |
Expand All @@ -72,4 +60,4 @@ jobs:
-v "$(pwd)":"/opt/src/mlir-tcp" \
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
mlir-tcp:ci \
bazel test @llvm-project//mlir/...
bazel test --test_output=errors @llvm-project//mlir/...
22 changes: 5 additions & 17 deletions .github/workflows/bazelBuildAndTestStablehlo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,12 @@ jobs:

steps:
- name: Checkout mlir-tcp
uses: actions/checkout@v3
uses: actions/checkout@v4

# Continually update cache even if there's a "hit" during
# restore to avoid the cache going stale over time
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
- name: Setup cache for bazel
uses: actions/cache@v3
- name: Setup workspace
uses: ./.github/actions/setup-build
with:
path: ~/.cache/bazel
key: stablehlo-bazel-build-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
stablehlo-bazel-build-cache-${{ runner.os }}
- name: Create bazel cache dir when not found
run: |
if [ ! -d "${HOME}/.cache/bazel" ]; then
mkdir -p "${HOME}/.cache/bazel"
fi
cache-prefix: 'stablehlo'

- name: Build docker image
run: |
Expand All @@ -72,4 +60,4 @@ jobs:
-v "$(pwd)":"/opt/src/mlir-tcp" \
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
mlir-tcp:ci \
bazel test @stablehlo//...
bazel test --test_output=errors @stablehlo//...
22 changes: 5 additions & 17 deletions .github/workflows/bazelBuildAndTestTcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,12 @@ jobs:

steps:
- name: Checkout mlir-tcp
uses: actions/checkout@v3
uses: actions/checkout@v4

# Continually update cache even if there's a "hit" during
# restore to avoid the cache going stale over time
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
- name: Setup cache for bazel
uses: actions/cache@v3
- name: Setup workspace
uses: ./.github/actions/setup-build
with:
path: ~/.cache/bazel
key: mlir-tcp-bazel-build-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
mlir-tcp-bazel-build-cache-${{ runner.os }}
- name: Create bazel cache dir when not found
run: |
if [ ! -d "${HOME}/.cache/bazel" ]; then
mkdir -p "${HOME}/.cache/bazel"
fi
cache-prefix: 'mlir-tcp'

- name: Build docker image
run: |
Expand Down Expand Up @@ -97,4 +85,4 @@ jobs:
-v "$(pwd)":"/opt/src/mlir-tcp" \
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
mlir-tcp:ci \
bazel test //test/...
bazel test --test_output=errors //...
22 changes: 5 additions & 17 deletions .github/workflows/bazelBuildAndTestTorchmlir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,12 @@ jobs:

steps:
- name: Checkout mlir-tcp
uses: actions/checkout@v3
uses: actions/checkout@v4

# Continually update cache even if there's a "hit" during
# restore to avoid the cache going stale over time
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache
- name: Setup cache for bazel
uses: actions/cache@v3
- name: Setup workspace
uses: ./.github/actions/setup-build
with:
path: ~/.cache/bazel
key: torch-mlir-bazel-build-cache-${{ runner.os }}-${{ github.sha }}
restore-keys: |
torch-mlir-bazel-build-cache-${{ runner.os }}
- name: Create bazel cache dir when not found
run: |
if [ ! -d "${HOME}/.cache/bazel" ]; then
mkdir -p "${HOME}/.cache/bazel"
fi
cache-prefix: 'torch-mlir'

- name: Build docker image
run: |
Expand All @@ -72,4 +60,4 @@ jobs:
-v "$(pwd)":"/opt/src/mlir-tcp" \
-v "${HOME}/.cache/bazel":"${HOME}/.cache/bazel" \
mlir-tcp:ci \
bazel test @torch-mlir//...
bazel test --test_output=errors @torch-mlir//...
5 changes: 5 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ package(
],
)

exports_files([
"requirements.txt",
"requirements_lock.txt",
])

td_library(
name = "TcpDialectTdFiles",
srcs = [
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bazel build //:tcp-opt

3. To run TCP lit and aot compile tests:
```shell
bazel test //test/...
bazel test //...
```

We welcome contributions to `mlir-tcp`. If you do contribute, please finalize your PR with clang-format and bazel buildifier to ensure the C++ sources and BUILD files are formatted consistently:
Expand Down Expand Up @@ -60,6 +60,11 @@ The following CI workflows are automatically triggered anytime upstream dependen
- [![Bazel Build and Test (torch-mlir)](https://github.com/cruise-automation/mlir-tcp/actions/workflows/bazelBuildAndTestTorchmlir.yml/badge.svg)](https://github.com/cruise-automation/mlir-tcp/actions/workflows/bazelBuildAndTestTorchmlir.yml)
- [![Bazel Build and Test (stablehlo)](https://github.com/cruise-automation/mlir-tcp/actions/workflows/bazelBuildAndTestStablehlo.yml/badge.svg)](https://github.com/cruise-automation/mlir-tcp/actions/workflows/bazelBuildAndTestStablehlo.yml)

To use newer `torch-mlir` and/or `torch` python packages in our hermetic python sandbox, just regenerate `requirements_lock.txt` as follows:
```shell
truncate -s 0 requirements_lock.txt
bazel run //tools/pip:requirements.update
```

## Debugging Guide

Expand Down
49 changes: 44 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,47 @@ torch_mlir_configure(name = "torch-mlir")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# -------------------------- #
# Hermetic Python Setup #
# -------------------------- #

RULES_PYTHON_VERSION = "0.29.0"

RULES_PYTHON_SHA256 = "d71d2c67e0bce986e1c5a7731b4693226867c45bfe0b7c5e0067228a536fc580"

http_archive(
name = "rules_python",
sha256 = RULES_PYTHON_SHA256,
strip_prefix = "rules_python-{}".format(RULES_PYTHON_VERSION),
url = "https://github.com/bazelbuild/rules_python/releases/download/{}/rules_python-{}.tar.gz".format(RULES_PYTHON_VERSION, RULES_PYTHON_VERSION),
)

load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()

load("@rules_python//python:repositories.bzl", "python_register_toolchains")

python_register_toolchains(
name = "python_3_10",
python_version = "3.10",
)

load("@python_3_10//:defs.bzl", "interpreter")
load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse(
name = "pip_deps",
python_interpreter_target = interpreter,
requirements_lock = "//:requirements_lock.txt",
)

load("@pip_deps//:requirements.bzl", "install_deps")

install_deps()

# --------------------------- #
# Buildifier dependencies #
# Buildifier Dependencies #
# --------------------------- #

# https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md
Expand Down Expand Up @@ -84,10 +123,10 @@ http_archive(
],
)

# ----------------------------- #
# Compile Commands Extractor #
# for Bazel (clangd) #
# ----------------------------- #
# ------------------------------------ #
# Bazel Compile Commands Extractor #
# for clangd #
# ------------------------------------ #

# https://github.com/hedronvision/bazel-compile-commands-extractor/blob/main/README.md

Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-f https://github.com/llvm/torch-mlir-release/releases/expanded_assets/dev-wheels
torch
torch-mlir
Loading

0 comments on commit 11f3e27

Please sign in to comment.