Skip to content

Commit 85d91a1

Browse files
authored
enable os-specific oneapi dependency versioning (#5467) + compile bundle (#5421) (#5493)
* enable os-specific oneapi dependency versioning (#5467) * change compile bundle to a cross-platform script * update dependency version
1 parent 2d19893 commit 85d91a1

16 files changed

+1583
-1426
lines changed

dependency_version.json

+19-13
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,42 @@
77
"commit": "llvmorg-16.0.6"
88
},
99
"pytorch": {
10-
"version": "2.6.0+xpu",
11-
"commit": "v2.6.0"
10+
"index-url": "https://download.pytorch.org/whl/xpu",
11+
"version": "2.8.0+xpu",
12+
"commit": "main"
1213
},
1314
"torchaudio": {
14-
"version": "2.6.0+xpu",
15-
"commit": "v2.6.0"
15+
"version": "2.8.0+xpu",
16+
"commit": "main"
1617
},
1718
"torchvision": {
18-
"version": "0.21.0+xpu",
19-
"commit": "v0.21.0"
19+
"version": "0.23.0+xpu",
20+
"commit": "main"
2021
},
2122
"torch-ccl": {
22-
"version": "2.6.0+xpu",
23-
"commit": "v2.6.0+xpu"
23+
"version": "2.8.0+xpu",
24+
"commit": "v2.8.0+xpu"
2425
},
2526
"basekit": {
2627
"dpcpp-cpp-rt": {
27-
"version": "2025.0"
28+
"linux": "2025.1",
29+
"windows": "2025.1"
2830
},
2931
"mkl-dpcpp": {
30-
"version": "2025.0.1"
32+
"linux": "2025.1",
33+
"windows": "2025.1"
3134
},
3235
"oneccl-devel": {
33-
"version": "2021.14.1"
36+
"linux": "2021.15.0",
37+
"windows": "N/A"
3438
},
3539
"impi-devel": {
36-
"version": "2021.14.1"
40+
"linux": "2021.15.0",
41+
"windows": "N/A"
3742
},
3843
"intel-pti": {
39-
"version": "0.10"
44+
"linux": "0.12",
45+
"windows": "0.12"
4046
}
4147
}
4248
}

docker/Dockerfile.compile

+29-9
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,42 @@ RUN bash ./basekit_driver_install_helper.sh driver
3535

3636
WORKDIR /root
3737

38-
RUN curl -fsSL -v -o miniforge.sh -O https://github.com/conda-forge/miniforge/releases/download/24.7.1-2/Miniforge3-24.7.1-2-Linux-x86_64.sh && \
38+
RUN curl -fsSL -v -o miniforge.sh -O https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh && \
3939
bash miniforge.sh -b -p ./miniforge3 && \
4040
rm miniforge.sh
4141

4242
FROM base AS dev
43-
ARG AOT=pytorch
43+
ARG AOT
4444
RUN bash /basekit_driver_install_helper.sh dev
4545
COPY . ./intel-extension-for-pytorch/
46-
RUN cp ./intel-extension-for-pytorch/scripts/compile_bundle.sh ./ && \
47-
sed -i "s/VER_IPEX=.*/VER_IPEX=/" compile_bundle.sh
4846
RUN . ./miniforge3/bin/activate && \
4947
conda create -y -n compile_py310 python=3.10 && conda activate compile_py310 && \
50-
bash compile_bundle.sh /opt/intel/oneapi ${AOT} && \
51-
mkdir wheels && find . -name "dist" -exec bash -c "cp {}/*.whl ./wheels" \; && \
52-
if [ "${AOT}" = "pytorch" ]; then cd intel-extension-for-pytorch; VERSION_TORCH=$(python ./scripts/tools/compilation_helper/dep_ver_utils.py -f dependency_version.json -k pytorch:version); VERSION_TORCHVISION=$(python ./scripts/tools/compilation_helper/dep_ver_utils.py -f dependency_version.json -k torchvision:version); VERSION_TORCHAUDIO=$(python ./scripts/tools/compilation_helper/dep_ver_utils.py -f dependency_version.json -k torchaudio:version); echo "#/bin/bash\npython -m pip install torch==${VERSION_TORCH} torchvision==${VERSION_TORCHVISION} torchaudio==${VERSION_TORCHAUDIO} --index-url https://download.pytorch.org/whl/xpu" > ../wheels/pytorch_install.sh; fi
48+
ARGS=""; \
49+
if [ ! -z "${AOT}" ]; then \
50+
ARGS="--install-pytorch compile --aot ${AOT}"; \
51+
fi; \
52+
python intel-extension-for-pytorch/scripts/compile_bundle.py ${ARGS} --with-vision --with-audio --with-torch-ccl /opt/intel/oneapi && \
53+
mkdir wheels && find . -maxdepth 2 -name "dist" -exec bash -c "cp {}/*.whl ./wheels" \; && \
54+
echo "#/bin/bash\n" > ./wheels/pytorch_install.sh; \
55+
echo 'BASEFOLDER=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}" )" &> /dev/null && pwd )\n' >> ./wheels/pytorch_install.sh; \
56+
echo 'cd ${BASEFOLDER}\n' >> ./wheels/pytorch_install.sh; \
57+
INDEX_URL=$(python ./intel-extension-for-pytorch/scripts/tools/compilation_helper/dep_ver_utils.py -f ./intel-extension-for-pytorch/dependency_version.json -k pytorch:index-url); \
58+
if [ ! -d pytorch ]; then \
59+
VERSION_TORCH=$(python ./intel-extension-for-pytorch/scripts/tools/compilation_helper/dep_ver_utils.py -f ./intel-extension-for-pytorch/dependency_version.json -k pytorch:version); \
60+
VERSION_TORCHVISION=$(python ./intel-extension-for-pytorch/scripts/tools/compilation_helper/dep_ver_utils.py -f ./intel-extension-for-pytorch/dependency_version.json -k torchvision:version); \
61+
VERSION_TORCHAUDIO=$(python ./intel-extension-for-pytorch/scripts/tools/compilation_helper/dep_ver_utils.py -f ./intel-extension-for-pytorch/dependency_version.json -k torchaudio:version); \
62+
echo "python -m pip install torch==${VERSION_TORCH} torchvision==${VERSION_TORCHVISION} torchaudio==${VERSION_TORCHAUDIO} --index-url ${INDEX_URL}\n" >> ./wheels/pytorch_install.sh; \
63+
fi; \
64+
echo "python -m pip install *.whl" >> ./wheels/pytorch_install.sh; \
65+
if [ -d pytorch ]; then \
66+
VER_FILE="./pytorch/.ci/docker/triton_version.txt"; \
67+
VER_TRITON=""; \
68+
if [ -f ${VER_FILE} ]; then \
69+
VER_TRITON="==$(cat ${VER_FILE})"; \
70+
fi; \
71+
echo "\n" >> ./wheels/pytorch_install.sh; \
72+
echo "python -m pip install pytorch-triton-xpu${VER_TRITON} --index-url ${INDEX_URL}" >> ./wheels/pytorch_install.sh; \
73+
fi;
5374

5475
FROM base AS deploy
5576
RUN apt clean && \
@@ -61,8 +82,7 @@ COPY --from=dev /root/intel-extension-for-pytorch/scripts/tools/compilation_help
6182
RUN . ./miniforge3/bin/activate && \
6283
conda create -y -n py310 python=3.10 && conda activate py310 && \
6384
conda install -y libstdcxx-ng libpng libjpeg-turbo && \
64-
if [ -f ./wheels/pytorch_install.sh ]; then bash ./wheels/pytorch_install.sh; fi && \
65-
python -m pip install ./wheels/*.whl && \
85+
bash ./wheels/pytorch_install.sh && \
6686
python -m pip cache purge && \
6787
conda clean -a -y && \
6888
rm -rf ./wheels

examples/gpu/llm/Dockerfile

+15-7
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,29 @@ RUN bash ./basekit_driver_install_helper.sh driver
3030

3131
WORKDIR /root
3232

33-
RUN curl -fsSL -v -o miniforge.sh -O https://github.com/conda-forge/miniforge/releases/download/24.7.1-2/Miniforge3-24.7.1-2-Linux-x86_64.sh && \
33+
RUN curl -fsSL -v -o miniforge.sh -O https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh && \
3434
bash miniforge.sh -b -p ./miniforge3 && \
3535
rm miniforge.sh
3636

3737
FROM base AS dev
3838
# --build-arg COMPILE=ON to compile from source
3939
ARG COMPILE
40-
ARG AOT=pytorch
41-
RUN bash /basekit_driver_install_helper.sh dev
40+
ARG AOT
4241
COPY . ./intel-extension-for-pytorch/
4342
RUN . ./miniforge3/bin/activate && \
43+
if [ ! -z "${COMPILE}" ]; then bash /basekit_driver_install_helper.sh dev; fi && \
4444
conda create -y -n compile_py310 python=3.10 && conda activate compile_py310 && \
45-
cd intel-extension-for-pytorch/examples/gpu/llm && \
46-
MODE=0; if [ -z ${COMPILE} ]; then (( MODE |= 0x06 )); else (( MODE |= 0x02 )); fi && \
47-
bash tools/env_setup.sh ${MODE} /opt/intel/oneapi ${AOT}
45+
ARGS="--setup"; \
46+
if [ ! -z "${COMPILE}" ] && \
47+
( [ "${COMPILE}" == "ON" ] || \
48+
[ "${COMPILE}" == "on" ] || \
49+
[ "${COMPILE}" == "1" ] ); then \
50+
if [ ! -z "${AOT}" ]; then \
51+
ARGS="${ARGS} --install-pytorch compile --aot ${AOT}"; \
52+
fi; \
53+
ARGS="${ARGS} --oneapi-root-dir /opt/intel/oneapi"; \
54+
fi; \
55+
python ./intel-extension-for-pytorch/examples/gpu/llm/tools/env_setup.py ${ARGS}
4856

4957
FROM base AS deploy
5058
COPY --from=dev /root/intel-extension-for-pytorch/examples/gpu/llm ./llm
@@ -56,7 +64,7 @@ RUN apt clean && \
5664
RUN . ./miniforge3/bin/activate && \
5765
conda create -y -n py310 python=3.10 && conda activate py310 && conda install -y libstdcxx-ng && \
5866
cd ./llm && \
59-
bash tools/env_setup.sh 1 && \
67+
python tools/env_setup.py --deploy && \
6068
python -m pip cache purge && \
6169
conda clean -a -y
6270
RUN ENTRYPOINT=/usr/local/bin/entrypoint.sh && \

examples/gpu/llm/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ conda activate llm
5151
# Setup the environment with the provided script
5252
cd examples/gpu/llm
5353
# If you want to install Intel® Extension for PyTorch\* from source, use the commands below:
54-
# e.g. bash ./tools/env_setup.sh 3 /opt/intel/oneapi pvc
55-
bash ./tools/env_setup.sh 3 <ONEAPI_ROOT_DIR> <AOT>
54+
# e.g. python ./tools/env_setup.py --setup --install-pytorch compile --aot pvc --oneapi-root-dir /opt/intel/oneapi --deploy
55+
python ./tools/env_setup.py --setup --install-pytorch compile --aot <AOT> --oneapi-root-dir <ONEAPI_ROOT_DIR> --deploy
5656

5757
conda deactivate
5858
conda activate llm
+208
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
#!/usr/bin/env python
2+
# encoding: utf-8
3+
4+
import os
5+
import platform
6+
import shutil
7+
import subprocess
8+
import stat
9+
import sys
10+
import time
11+
12+
SYSTEM = platform.system()
13+
14+
def _exec_cmd_single(command,
15+
cwd = None,
16+
env = None,
17+
shell = False,
18+
level = 1,
19+
exit_on_failure = True,
20+
show_command = False,
21+
silent = False,
22+
redirect_file = '',
23+
redirect_append = False):
24+
if command == '':
25+
return 0, []
26+
file = None
27+
if redirect_file != '':
28+
if redirect_append:
29+
file = open(redirect_file, 'a')
30+
else:
31+
file = open(redirect_file, 'w')
32+
cmd = None
33+
if shell:
34+
cmd = command.strip()
35+
else:
36+
cmd = command.strip().split()
37+
if show_command:
38+
if not silent:
39+
print(f'{"+" * level} {command}')
40+
if not file is None:
41+
file.write(f'{"+" * level} {command}\n')
42+
lines_stdout = []
43+
p = subprocess.Popen(cmd,
44+
cwd = cwd,
45+
stdout = subprocess.PIPE,
46+
stderr = subprocess.STDOUT,
47+
env = env,
48+
shell = shell,
49+
text = True)
50+
for line in iter(p.stdout.readline, ''):
51+
lines_stdout.append(line.strip())
52+
if not silent:
53+
print(line, end = '')
54+
if not file is None:
55+
file.write(line)
56+
p.stdout.close()
57+
return_code = p.wait()
58+
if file is not None:
59+
file.close()
60+
if exit_on_failure:
61+
assert p.returncode == 0, f'Command [{command.strip()}] execution failed.'
62+
return p.returncode, lines_stdout
63+
64+
def exec_cmds(commands,
65+
cwd = None,
66+
env = None,
67+
shell = False,
68+
exit_on_failure = True,
69+
stop_on_failure = True,
70+
show_command = False,
71+
silent = False,
72+
redirect_file = '',
73+
redirect_append = False):
74+
if show_command:
75+
silent = False
76+
if redirect_file != '':
77+
if not redirect_append and os.path.exists(redirect_file):
78+
os.remove(redirect_file)
79+
redirect_append = True
80+
ret_code = 0
81+
ret_lines = []
82+
cmds = []
83+
for c in commands.split('\n'):
84+
c = c.strip()
85+
if c != '':
86+
cmds.append(c)
87+
for cmd in cmds:
88+
r, lines_stdout = _exec_cmd_single(cmd,
89+
cwd = cwd,
90+
env = env,
91+
shell = shell,
92+
show_command = show_command,
93+
exit_on_failure = exit_on_failure,
94+
silent = silent,
95+
redirect_file = redirect_file,
96+
redirect_append = redirect_append)
97+
ret_code = r
98+
ret_lines += lines_stdout
99+
if stop_on_failure and r > 0 and len(cmds) > 1:
100+
print('Execution failed!')
101+
break
102+
return ret_code, ret_lines
103+
104+
def check_system_commands(commands):
105+
absent = 0
106+
ret = {}
107+
for cmd in commands:
108+
ret[cmd] = shutil.which(cmd)
109+
if not ret[cmd]:
110+
print(f'{cmd} not found.')
111+
absent += 1
112+
assert absent == 0, 'Required system command(s) not found.'
113+
return ret
114+
115+
def remove_directory(directory):
116+
if SYSTEM == 'Windows':
117+
for root, dirs, files in os.walk(directory):
118+
for dir_name in dirs:
119+
dir_path = os.path.join(root, dir_name)
120+
os.chmod(dir_path, stat.S_IWRITE)
121+
for file_name in files:
122+
file_path = os.path.join(root, file_name)
123+
os.chmod(file_path, stat.S_IWRITE)
124+
shutil.rmtree(directory)
125+
126+
def remove_file_dir(item):
127+
if os.path.isfile(item):
128+
os.remove(item)
129+
elif os.path.isdir(item):
130+
remove_directory(item)
131+
else:
132+
pass
133+
134+
def clear_directory(directory):
135+
for item in os.listdir(directory):
136+
if item.startswith("."):
137+
continue
138+
remove_file_dir(os.path.join(directory, item))
139+
140+
def update_source_code(dir_name,
141+
url_repo,
142+
branch,
143+
branch_main = 'main',
144+
basedir = '',
145+
show_command = False):
146+
print(f'========== {dir_name} ==========')
147+
dir_target = os.path.join(basedir, dir_name)
148+
if not os.path.isdir(dir_target):
149+
exec_cmds(f'git clone {url_repo} {dir_name}',
150+
cwd=basedir,
151+
show_command = show_command)
152+
if branch != '':
153+
clear_directory(dir_target)
154+
exec_cmds(f'''git checkout .
155+
git checkout {branch_main}
156+
git pull''',
157+
cwd = dir_target,
158+
silent = True)
159+
exec_cmds(f'git checkout {branch}',
160+
cwd = dir_target,
161+
show_command = show_command)
162+
exec_cmds('''git submodule sync
163+
git submodule update --init --recursive''',
164+
cwd = dir_target,
165+
show_command = show_command)
166+
167+
def source_env(script,
168+
env = None,
169+
show_command = False):
170+
if script == '' or not os.path.exists(script):
171+
print(f'Incorrect script: {script}')
172+
return None
173+
if env is None:
174+
env = os.environ.copy()
175+
separator = '========== SEPARATOR =========='
176+
command = ''
177+
if SYSTEM == 'Linux':
178+
command = f'. {script} && echo "{separator}" && env'
179+
elif SYSTEM == 'Windows':
180+
command = f'cmd.exe /c ""{script}" && echo {separator} && set"'
181+
else:
182+
pass
183+
if show_command:
184+
print(f'+ {command.split("&&")[0].strip()}')
185+
_, lines_stdout = exec_cmds(command,
186+
env = env,
187+
shell = True,
188+
silent = True)
189+
parse_start = False
190+
for line in lines_stdout:
191+
if parse_start:
192+
key, value = line.strip().split('=', 1)
193+
env[key] = value
194+
if line.strip() == separator:
195+
parse_start = True
196+
return env
197+
198+
def get_duration(t0):
199+
t1 = int(time.time() * 1000)
200+
return (t1 - t0) / 1000.0
201+
202+
def download(url, filepath):
203+
import requests
204+
response = requests.get(url, stream=True)
205+
assert response.status_code >= 200 and response.status_code < 300, f'Failed to download {url}.'
206+
with open(filepath, 'wb') as file:
207+
for chunk in response.iter_content(chunk_size=8192):
208+
file.write(chunk)

0 commit comments

Comments
 (0)