Skip to content

Commit 34105b5

Browse files
authored
[ODSC-48942]opctl create/publish error on M1 and M2 (#381)
2 parents 4d10e47 + 8a57a5d commit 34105b5

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

THIRD_PARTY_LICENSES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ psutil
241241
* Source code: https://github.com/giampaolo/psutil
242242
* Project home: https://github.com/giampaolo/psutil
243243

244+
py-cpuinfo
245+
* Copyright (c) 2014-2022 Matthew Brennan Jones <matthew.brennan.jones@gmail.com>
246+
* License: The MIT License (MIT)
247+
* Source code: https://github.com/workhorsy/py-cpuinfo
248+
* Project home: https://github.com/workhorsy/py-cpuinfo
249+
244250
pyspark
245251
* Copyright 2014 and onwards The Apache Software Foundation.
246252
* License: Apache-2.0 LICENSE

ads/opctl/conda/cmds.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,10 @@ def _publish(
638638
)
639639
except Exception:
640640
raise RuntimeError(f"Could not pack environment {conda_slug}.")
641+
NOT_ALLOWED_CHARS = "@#$%^&*/"
641642

643+
if any(chr in conda_slug for chr in NOT_ALLOWED_CHARS):
644+
raise ValueError(f"Invalid conda_slug. Found {NOT_ALLOWED_CHARS} in slug name. Please use a different slug name.")
642645
pack_file = os.path.join(pack_folder_path, f"{conda_slug}.tar.gz")
643646
if not os.path.exists(pack_file):
644647
raise RuntimeError(f"Pack {pack_file} was not created.")

ads/opctl/conda/pack.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ def main(pack_folder_path, manifest_file=None):
2626
)
2727
with open(manifest_path) as f:
2828
env = yaml.safe_load(f.read())
29-
29+
3030
with tempfile.TemporaryDirectory() as td:
3131
process = subprocess.Popen(
3232
["conda", "env", "export", "--prefix", pack_folder_path],
3333
stdout=subprocess.PIPE,
3434
stderr=subprocess.PIPE,
3535
)
3636
stdout, stderr = process.communicate()
37-
if stderr:
37+
38+
if process.returncode and stderr:
3839
print(stderr)
3940
raise Exception(
4041
f"Error export environment information from {pack_folder_path}"

ads/opctl/docker/Dockerfile.job

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ RUN rm -rf /tmp/*
100100

101101
RUN mkdir -p /etc/datascience/operators
102102

103-
USER datascience
103+
USER datascience

ads/opctl/utils.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from subprocess import Popen, PIPE, STDOUT
1818
from typing import Union, List, Tuple, Dict
1919
import yaml
20+
import re
2021

2122
import ads
2223
from ads.common.oci_client import OCIClientFactory
@@ -160,7 +161,14 @@ def build_image(
160161
)
161162
proc = _build_custom_operator_image(gpu, source_folder, dst_image)
162163
else:
163-
image, dockerfile, target = _get_image_name_dockerfile_target(image_type, gpu)
164+
# https://stackoverflow.com/questions/66842004/get-the-processor-type-using-python-for-apple-m1-processor-gives-me-an-intel-pro
165+
import cpuinfo
166+
# Just get the manufacturer of the processors
167+
manufacturer = cpuinfo.get_cpu_info().get('brand_raw')
168+
arch = 'arm' if re.search("apple m\d ", manufacturer, re.IGNORECASE) else 'other'
169+
print(f"The local machine's platform is {arch}.")
170+
image, dockerfile, target = _get_image_name_dockerfile_target(image_type, gpu, arch)
171+
print(f"dockerfile used is {dockerfile}")
164172
command = [
165173
"docker",
166174
"build",
@@ -186,14 +194,15 @@ def build_image(
186194
raise RuntimeError("Docker build failed.")
187195

188196

189-
def _get_image_name_dockerfile_target(type: str, gpu: bool) -> str:
197+
def _get_image_name_dockerfile_target(type: str, gpu: bool, arch: str) -> str:
190198
look_up = {
191-
("job-local", False): (ML_JOB_IMAGE, "Dockerfile.job", None),
192-
("job-local", True): (ML_JOB_GPU_IMAGE, "Dockerfile.job.gpu", None),
193-
("ads-ops-base", False): (OPS_IMAGE_BASE, "Dockerfile", "base"),
194-
("ads-ops-base", True): (OPS_IMAGE_GPU_BASE, "Dockerfile.gpu", "base"),
199+
("job-local", False, "arm"): (ML_JOB_IMAGE, "Dockerfile.job.arm", None),
200+
("job-local", False, "other"): (ML_JOB_IMAGE, "Dockerfile.job", None),
201+
("job-local", True, "other"): (ML_JOB_GPU_IMAGE, "Dockerfile.job.gpu", None),
202+
("ads-ops-base", False, "other"): (OPS_IMAGE_BASE, "Dockerfile", "base"),
203+
("ads-ops-base", True, "other"): (OPS_IMAGE_GPU_BASE, "Dockerfile.gpu", "base"),
195204
}
196-
return look_up[(type, gpu)]
205+
return look_up[(type, gpu, arch)]
197206

198207

199208
@runtime_dependency(module="docker", install_from=OptionalDependency.OPCTL)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ opctl = [
123123
"nbconvert",
124124
"nbformat",
125125
"oci-cli",
126+
"py-cpuinfo",
126127
]
127128
optuna = [
128129
"optuna==2.9.0",

0 commit comments

Comments
 (0)