Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ODSC-48942]opctl create/publish error on M1 and M2 #381

Merged
merged 10 commits into from
Nov 15, 2023
3 changes: 2 additions & 1 deletion ads/opctl/conda/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,8 @@ def _publish(
)
except Exception:
raise RuntimeError(f"Could not pack environment {conda_slug}.")

if "/" in conda_slug:
z7ye marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError("Invalid conda_slug. found `/` in slug name. Please use a different slug name.")
pack_file = os.path.join(pack_folder_path, f"{conda_slug}.tar.gz")
if not os.path.exists(pack_file):
raise RuntimeError(f"Pack {pack_file} was not created.")
Expand Down
5 changes: 3 additions & 2 deletions ads/opctl/conda/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ def main(pack_folder_path, manifest_file=None):
)
with open(manifest_path) as f:
env = yaml.safe_load(f.read())

with tempfile.TemporaryDirectory() as td:
process = subprocess.Popen(
["conda", "env", "export", "--prefix", pack_folder_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = process.communicate()
if stderr:

if process.returncode and stderr:
print(stderr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use logger for debug purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember we could only use print() to show the msgs when running this code in container?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep yep, you are right.

raise Exception(
f"Error export environment information from {pack_folder_path}"
Expand Down
2 changes: 1 addition & 1 deletion ads/opctl/docker/Dockerfile.job
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ RUN rm -rf /tmp/*

RUN mkdir -p /etc/datascience/operators

USER datascience
USER datascience
23 changes: 16 additions & 7 deletions ads/opctl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from subprocess import Popen, PIPE, STDOUT
from typing import Union, List, Tuple, Dict
import yaml
import re

import ads
from ads.common.oci_client import OCIClientFactory
Expand Down Expand Up @@ -161,7 +162,14 @@ def build_image(
)
proc = _build_custom_operator_image(gpu, source_folder, dst_image)
else:
image, dockerfile, target = _get_image_name_dockerfile_target(image_type, gpu)
# https://stackoverflow.com/questions/66842004/get-the-processor-type-using-python-for-apple-m1-processor-gives-me-an-intel-pro
import cpuinfo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to create a separate function - _get_architecture()? We probably will reuse this method in different other places.

# Just get the manufacturer of the processors
manufacturer = cpuinfo.get_cpu_info().get('brand_raw')
arch = 'arm' if re.search("apple m\d ", manufacturer, re.IGNORECASE) else 'other'
print(f"The local machine's platform is {arch}.")
image, dockerfile, target = _get_image_name_dockerfile_target(image_type, gpu, arch)
print(f"dockerfile used is {dockerfile}")
command = [
"docker",
"build",
Expand All @@ -187,14 +195,15 @@ def build_image(
raise RuntimeError("Docker build failed.")


def _get_image_name_dockerfile_target(type: str, gpu: bool) -> str:
def _get_image_name_dockerfile_target(type: str, gpu: bool, arch: str) -> str:
look_up = {
("job-local", False): (ML_JOB_IMAGE, "Dockerfile.job", None),
("job-local", True): (ML_JOB_GPU_IMAGE, "Dockerfile.job.gpu", None),
("ads-ops-base", False): (OPS_IMAGE_BASE, "Dockerfile", "base"),
("ads-ops-base", True): (OPS_IMAGE_GPU_BASE, "Dockerfile.gpu", "base"),
("job-local", False, "arm"): (ML_JOB_IMAGE, "Dockerfile.job.arm", None),
("job-local", False, "other"): (ML_JOB_IMAGE, "Dockerfile.job", None),
("job-local", True, "other"): (ML_JOB_GPU_IMAGE, "Dockerfile.job.gpu", None),
("ads-ops-base", False, "other"): (OPS_IMAGE_BASE, "Dockerfile", "base"),
("ads-ops-base", True, "other"): (OPS_IMAGE_GPU_BASE, "Dockerfile.gpu", "base"),
}
return look_up[(type, gpu)]
return look_up[(type, gpu, arch)]


@runtime_dependency(module="docker", install_from=OptionalDependency.OPCTL)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ opctl = [
"nbconvert",
"nbformat",
"oci-cli",
"py-cpuinfo",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

]
optuna = [
"optuna==2.9.0",
Expand Down