Skip to content

Commit 9666738

Browse files
committed
feat: add Helion setup script for modular installation
Add scripts/setup_helion.sh to support Helion installation and configuration within containers. This script: - Downloads Helion source from GitHub when not mounted as a volume - Installs build dependencies for Helion compilation - Supports installing Helion wheels from PyPI (release, nightly) - Provides flexible configuration via INSTALL_HELION environment variable The script supports multiple installation modes: - source: Build from source (with auto-download if not mounted) - release/nightly: Install wheels from PyPI - skip: Skip Helion installation This is part of the modular script architecture introduced in PR #115. Signed-off-by: Craig Magina <cmagina@redhat.com>
1 parent d5c4916 commit 9666738

9 files changed

Lines changed: 172 additions & 1 deletion

File tree

.github/workflows/amd-image.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on: # yamllint disable-line rule:truthy
1111
- scripts/install_software.sh
1212
- scripts/ldpretend.sh
1313
- scripts/setup_llvm.sh
14+
- scripts/setup_helion.sh
1415
- scripts/setup_torch.sh
1516
- scripts/setup_triton.sh
1617
- scripts/setup_user.sh
@@ -23,6 +24,7 @@ on: # yamllint disable-line rule:truthy
2324
- scripts/install_software.sh
2425
- scripts/ldpretend.sh
2526
- scripts/setup_llvm.sh
27+
- scripts/setup_helion.sh
2628
- scripts/setup_torch.sh
2729
- scripts/setup_triton.sh
2830
- scripts/setup_user.sh

.github/workflows/cpu-image.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on: # yamllint disable-line rule:truthy
1111
- scripts/install_software.sh
1212
- scripts/ldpretend.sh
1313
- scripts/setup_llvm.sh
14+
- scripts/setup_helion.sh
1415
- scripts/setup_torch.sh
1516
- scripts/setup_triton.sh
1617
- scripts/setup_user.sh
@@ -23,6 +24,7 @@ on: # yamllint disable-line rule:truthy
2324
- scripts/install_software.sh
2425
- scripts/ldpretend.sh
2526
- scripts/setup_llvm.sh
27+
- scripts/setup_helion.sh
2628
- scripts/setup_torch.sh
2729
- scripts/setup_triton.sh
2830
- scripts/setup_user.sh

.github/workflows/nvidia-image.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on: # yamllint disable-line rule:truthy
1111
- scripts/install_software.sh
1212
- scripts/ldpretend.sh
1313
- scripts/setup_llvm.sh
14+
- scripts/setup_helion.sh
1415
- scripts/setup_torch.sh
1516
- scripts/setup_triton.sh
1617
- scripts/setup_user.sh
@@ -23,6 +24,7 @@ on: # yamllint disable-line rule:truthy
2324
- scripts/install_software.sh
2425
- scripts/ldpretend.sh
2526
- scripts/setup_llvm.sh
27+
- scripts/setup_helion.sh
2628
- scripts/setup_torch.sh
2729
- scripts/setup_triton.sh
2830
- scripts/setup_user.sh

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ create_user ?=true
4444
# NOTE: Requires host build system to have a valid Red Hat Subscription if true
4545
INSTALL_NSIGHT ?=false
4646
llvm_path ?=
47+
helion_path ?=
4748
torch_path ?=
4849
user_path ?=
50+
INSTALL_HELION ?= skip # Options: release, source, skip
4951
INSTALL_LLVM ?= skip # Options: source, skip
5052
INSTALL_TORCH ?= skip # Options: nightly, release, source, skip, test
5153
INSTALL_TRITON ?= source # Options: release, source, skip
@@ -121,6 +123,9 @@ define run_container
121123
if [ -n "$(llvm_path)" ]; then \
122124
volume_arg+=" -v $(llvm_path):/workspace/llvm-project$(SELINUXFLAG)"; \
123125
fi; \
126+
if [ -n "$(helion_path)" ]; then \
127+
volume_arg+=" -v $(helion_path):/workspace/helion$(SELINUXFLAG)"; \
128+
fi; \
124129
if [ -n "$(torch_path)" ]; then \
125130
volume_arg+=" -v $(torch_path):/workspace/torch$(SELINUXFLAG)"; \
126131
fi; \
@@ -165,7 +170,7 @@ define run_container
165170
if [ "$(CUSTOM_LLVM)" = "false" ]; then \
166171
install_llvm="-e INSTALL_LLVM=$(INSTALL_LLVM)"; \
167172
fi; \
168-
env_vars="-e USERNAME=$(USER) -e TORCH_VERSION=$(torch_version) -e CUSTOM_LLVM=$(CUSTOM_LLVM) -e INSTALL_TOOLS=$(DEMO_TOOLS) -e INSTALL_JUPYTER=$(INSTALL_JUPYTER) -e NOTEBOOK_PORT=$(NOTEBOOK_PORT) -e INSTALL_TORCH=$(INSTALL_TORCH) -e INSTALL_TRITON=$(INSTALL_TRITON) -e USE_CCACHE=$(USE_CCACHE) -e MAX_JOBS=$(MAX_JOBS)"; \
173+
env_vars="-e USERNAME=$(USER) -e TORCH_VERSION=$(torch_version) -e CUSTOM_LLVM=$(CUSTOM_LLVM) -e INSTALL_TOOLS=$(DEMO_TOOLS) -e INSTALL_JUPYTER=$(INSTALL_JUPYTER) -e NOTEBOOK_PORT=$(NOTEBOOK_PORT) -e INSTALL_HELION=$(INSTALL_HELION) -e INSTALL_TORCH=$(INSTALL_TORCH) -e INSTALL_TRITON=$(INSTALL_TRITON) -e USE_CCACHE=$(USE_CCACHE) -e MAX_JOBS=$(MAX_JOBS)"; \
169174
if [ "$(create_user)" = "true" ]; then \
170175
$(CTR_CMD) run -e CREATE_USER=$(create_user) $$env_vars $$install_llvm $$port_arg \
171176
-e USER_UID=`id -u $(USER)` -e USER_GID=`id -g $(USER)` $$gpu_args $$profiling_args $$keep_ns_arg \

dockerfiles/Dockerfile.triton

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ ENV BASH_ENV=/workspace/bin/activate \
6565
UV_HTTP_TIMEOUT=60
6666

6767
COPY --from=quay.io/triton-dev-containers/gosu /usr/local/bin/gosu /usr/local/bin/gosu
68+
COPY scripts/setup_helion.sh setup_helion.sh
6869
COPY scripts/setup_llvm.sh setup_llvm.sh
6970
COPY scripts/setup_torch.sh setup_torch.sh
7071
COPY scripts/setup_triton.sh setup_triton.sh

dockerfiles/Dockerfile.triton-amd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ ENV BASH_ENV=/workspace/bin/activate \
8383
WORKDIR /workspace
8484

8585
COPY --from=quay.io/triton-dev-containers/gosu /usr/local/bin/gosu /usr/local/bin/gosu
86+
COPY scripts/setup_helion.sh setup_helion.sh
8687
COPY scripts/setup_llvm.sh setup_llvm.sh
8788
COPY scripts/setup_torch.sh setup_torch.sh
8889
COPY scripts/setup_triton.sh setup_triton.sh

dockerfiles/Dockerfile.triton-cpu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ ENV BASH_ENV=/workspace/bin/activate \
6262
WORKDIR /workspace
6363

6464
COPY --from=quay.io/triton-dev-containers/gosu /usr/local/bin/gosu /usr/local/bin/gosu
65+
COPY scripts/setup_helion.sh setup_helion.sh
6566
COPY scripts/setup_llvm.sh setup_llvm.sh
6667
COPY scripts/setup_torch.sh setup_torch.sh
6768
COPY scripts/setup_triton.sh setup_triton.sh

scripts/setup.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ declare -a SAVE_VARS=(
2525
"DISPLAY"
2626
"HOME"
2727
"INSTALL_JUPYTER"
28+
"INSTALL_HELION"
2829
"INSTALL_LLVM"
2930
"INSTALL_TOOLS"
3031
"INSTALL_TORCH"
@@ -68,6 +69,10 @@ if [ "${INSTALL_LLVM:-skip}" != "skip" ]; then
6869
run_as_user ./setup_llvm.sh "$INSTALL_LLVM"
6970
fi
7071

72+
if [ "${INSTALL_HELION:-skip}" != "skip" ]; then
73+
run_as_user ./setup_helion.sh "$INSTALL_HELION"
74+
fi
75+
7176
if [ "${INSTALL_TRITON:-skip}" != "skip" ]; then
7277
run_as_user ./setup_triton.sh "$INSTALL_TRITON"
7378
fi

scripts/setup_helion.sh

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#! /bin/bash -e
2+
3+
trap "echo -e '\nScript interrupted. Exiting gracefully.'; exit 1" SIGINT
4+
5+
# Copyright (C) 2024-2025 Red Hat, Inc.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# SPDX-License-Identifier: Apache-2.0
20+
set -euo pipefail
21+
22+
WORKSPACE=${WORKSPACE:-${HOME}}
23+
24+
HELION_DIR=${WORKSPACE}/helion
25+
HELION_REPO=https://github.com/pytorch/helion.git
26+
27+
declare -a PIP_INSTALL_ARGS
28+
29+
# Extract the major.minor version from ROCM_VERSION, e.g. 6.4 from 6.4.4
30+
get_rocm_version() {
31+
[[ "$ROCM_VERSION" =~ ^([0-9]+\.[0-9]+) ]] && echo "${BASH_REMATCH[1]}" ||
32+
echo "$ROCM_VERSION"
33+
}
34+
35+
pip_install() {
36+
if command -v uv &>/dev/null; then
37+
uv pip install "$@"
38+
else
39+
pip install "$@"
40+
fi
41+
}
42+
43+
setup_src() {
44+
echo "Downloading Helion source code and setting up the environment for building from source..."
45+
46+
if [ ! -d "$HELION_DIR" ]; then
47+
echo "Cloning the Helion repo $HELION_REPO to $HELION_DIR ..."
48+
git clone "$HELION_REPO" "$HELION_DIR"
49+
if [ ! -d "$HELION_DIR" ]; then
50+
echo "$HELION_DIR not found. ERROR Cloning repository..."
51+
exit 1
52+
else
53+
pushd "$HELION_DIR" 1>/dev/null || exit 1
54+
git submodule sync
55+
git submodule update --init --recursive
56+
57+
if [ -n "${HELION_GITREF:-}" ]; then
58+
git checkout "$HELION_GITREF"
59+
fi
60+
61+
echo "Installing pre-commit hooks into your local Helion git repo (one-time)"
62+
pip_install pre-commit
63+
pre-commit install
64+
popd 1>/dev/null
65+
fi
66+
else
67+
echo "Torch repo already present, not cloning ..."
68+
fi
69+
}
70+
71+
install_deps() {
72+
echo "Installing Helion dependencies ..."
73+
pip_install numpy
74+
75+
"${WORKSPACE}"/setup_torch.sh release
76+
}
77+
78+
install_release() {
79+
echo "Installing Helion from PyPI ..."
80+
81+
if command -v uv &>/dev/null; then
82+
if [ -n "${UV_TORCH_BACKEND:-}" ]; then
83+
echo "Using the specified uv backend, $UV_TORCH_BACKEND"
84+
elif [ -n "${ROCM_VERSION:-}" ]; then
85+
echo "Using the torch ROCm version $ROCM_VERSION backend"
86+
UV_TORCH_BACKEND="rocm$(get_rocm_version)"
87+
elif ((${TRITON_CPU_BACKEND:-0} == 1)); then
88+
echo "Using the torch CPU backend"
89+
UV_TORCH_BACKEND=cpu
90+
elif [ -n "${CUDA_VERSION:-}" ]; then
91+
echo "Using the torch CUDA version $CUDA_VERSION backend"
92+
UV_TORCH_BACKEND="cu${CUDA_VERSION/[.-]/}"
93+
else
94+
echo "Using the torch auto backend"
95+
UV_TORCH_BACKEND=auto
96+
fi
97+
98+
PIP_INSTALL_ARGS+=("--torch-backend" "$UV_TORCH_BACKEND")
99+
elif ! command -v uv &>/dev/null && [ -n "${UV_TORCH_BACKEND:-}" ]; then
100+
echo "Error: UV_TORCH_BACKEND is set to $UV_TORCH_BACKEND but uv is not available."
101+
exit 1
102+
fi
103+
104+
if [ -n "${PIP_HELION_INDEX_URL:-}" ]; then
105+
echo "Using the specified index, $PIP_HELION_INDEX_URL"
106+
PIP_INSTALL_ARGS+=("--index-url $PIP_HELION_INDEX_URL")
107+
fi
108+
109+
if [ -n "${PIP_HELION_VERSION:-}" ]; then
110+
echo "Installing the specified Helion version $PIP_HELION_VERSION"
111+
PIP_HELION_VERSION="==$PIP_HELION_VERSION"
112+
fi
113+
114+
pip_install "${PIP_INSTALL_ARGS[@]}" "helion${PIP_HELION_VERSION:-}"
115+
116+
# Fix up LD_LIBRARY_PATH for CUDA
117+
"${WORKSPACE}"/ldpretend.sh
118+
}
119+
120+
usage() {
121+
cat >&2 <<EOF
122+
Usage: $(basename "$0") [COMMAND]
123+
source Download Helion's source (if needed) and install the build deps
124+
release Install Helion
125+
EOF
126+
}
127+
128+
##
129+
## Main
130+
##
131+
132+
if [ $# -ne 1 ]; then
133+
usage
134+
exit 1
135+
fi
136+
137+
COMMAND=${1,,}
138+
139+
case $COMMAND in
140+
source)
141+
setup_src
142+
install_deps
143+
;;
144+
release)
145+
install_deps
146+
install_release
147+
;;
148+
*)
149+
usage
150+
exit 1
151+
;;
152+
esac

0 commit comments

Comments
 (0)