Skip to content

Commit 80c5b76

Browse files
authored
[mac-ai] Work on a releasing mechanism (openshift-psap#773)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added options for building and publishing remoting tarballs and container images, with enhanced configuration for image registries and publishing credentials. - Introduced new script to automate Podman machine setup for remoting scenarios on macOS. - Added new test configuration presets for remoting, publishing, and testing scenarios. - Added new remote image login and push capabilities for container management. - **Improvements** - Enhanced flexibility for command execution and remote access by allowing control over output decoding and secret handling. - Modularized and improved logic for cloning, building, and patching source code and dependencies, ensuring fresh builds and consistent environment setup. - Updated preparation steps to always perform forced cloning and builds for consistency. - Improved platform parsing and validation for better error handling and clarity. - Refined remoting environment checks to activate only when remoting is in use. - Made container image versioning more configurable with build arguments. - Added control over decoding subprocess output to better handle raw or decoded output as needed. - Enhanced plotting logic to better handle missing or empty benchmark data. - Added automated creation of a comprehensive remoting release tarball with detailed setup instructions and metadata. - **Bug Fixes** - Fixed platform flavor assignment to prevent errors when parsing incomplete platform strings. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents ebb7e65 + 0614fd4 commit 80c5b76

File tree

16 files changed

+525
-69
lines changed

16 files changed

+525
-69
lines changed

projects/core/library/run.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def run_toolbox(group, command, artifact_dir_suffix=None, run_kwargs=None, mute_
102102
return run(f'{cmd_env} ./run_toolbox.py {group} {command} {_dict_to_run_toolbox_args(kwargs)}', **run_kwargs)
103103

104104

105-
def run(command, capture_stdout=False, capture_stderr=False, check=True, protect_shell=True, cwd=None, stdin_file=None, log_command=True):
105+
def run(command, capture_stdout=False, capture_stderr=False, check=True, protect_shell=True, cwd=None, stdin_file=None, log_command=True, decode_stdout=True, decode_stderr=True):
106106
if log_command:
107107
logging.info(f"run: {command}")
108108

@@ -124,8 +124,8 @@ def run(command, capture_stdout=False, capture_stderr=False, check=True, protect
124124

125125
proc = subprocess.run(command, **args)
126126

127-
if capture_stdout: proc.stdout = proc.stdout.decode("utf8")
128-
if capture_stderr: proc.stderr = proc.stderr.decode("utf8")
127+
if capture_stdout and decode_stdout: proc.stdout = proc.stdout.decode("utf8")
128+
if capture_stderr and decode_stderr: proc.stderr = proc.stderr.decode("utf8")
129129

130130
return proc
131131

projects/mac_ai/testing/config.yaml

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,38 @@ ci_presets:
8787
# ---
8888

8989
remoting:
90-
test.platform:
91-
- podman/llama_cpp/remoting
92-
- macos/llama_cpp/metal
93-
- podman/llama_cpp/vulkan
9490
prepare.llama_cpp.source.repo.url: https://github.com/kpouget/llama.cpp
9591
prepare.llama_cpp.source.repo.version: main
9692
prepare.podman.machine.remoting_env.enabled: true
9793
prepare.virglrenderer.enabled: true
9894

95+
remoting_publish:
96+
extends: [remoting]
97+
prepare.remoting.publish: true
98+
prepare.llama_cpp.source.repo.version: b5709-v250627
99+
prepare.virglrenderer.repo.branch: v25-06-18
100+
prepare.ramalama.build_image.enabled: "remoting"
101+
prepare.ramalama.build_image.publish.enabled: true
102+
prepare.ramalama.build_image.registry_path: quay.io/crcont
103+
prepare.ramalama.build_image.name: remoting
104+
prepare.ramalama.repo.url: https://github.com/kpouget/ramalama
105+
prepare.ramalama.repo.git_ref: v0.9.3-remoting-rc5
106+
prepare.ramalama.repo.version: null
107+
108+
test.platform:
109+
- podman/ramalama/remoting
110+
- podman/llama_cpp/remoting
111+
- macos/llama_cpp/metal
112+
- macos/llama_cpp/vulkan
113+
# - podman/llama_cpp/vulkan # not working today
114+
115+
remoting_testing:
116+
extends: [remoting]
117+
test.platform:
118+
- podman/llama_cpp/remoting
119+
- macos/llama_cpp/metal
120+
- podman/llama_cpp/vulkan
121+
99122
llama_cpp:
100123
test.platform:
101124
- macos/llama_cpp/metal
@@ -192,6 +215,7 @@ secrets:
192215
username: mac_ai__username.mac-m4
193216
base_work_dir: mac_ai__base_work_dir.mac-m4
194217
opensearch_instances: opensearch.yaml
218+
image_registry: quay-push.yaml
195219

196220
remote_host:
197221
run_locally: false
@@ -290,7 +314,10 @@ prepare:
290314
build_image:
291315
enabled: false
292316
name: ramalama
293-
317+
registry_path: localhost
318+
publish:
319+
enabled: false
320+
credentials: "*[email protected]_registry"
294321
brew:
295322
install_dependencies: false
296323
capture_dependencies: false
@@ -366,6 +393,9 @@ prepare:
366393
APIR_LLAMA_CPP_GGML_LIBRARY_REG: ggml_backend_metal_reg
367394
APIR_LLAMA_CPP_GGML_LIBRARY_INIT: ggml_backend_metal_init
368395

396+
remoting:
397+
publish: false
398+
369399
test:
370400
platform: *all_platforms
371401

@@ -505,3 +535,4 @@ __platform_check:
505535

506536
flavors:
507537
llama_cpp: [metal, vulkan, upstream_bin, kompute, remoting]
538+
ramalama: [remoting, null]

projects/mac_ai/testing/images/llama_cpp.containerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ FROM quay.io/centos/centos:10 AS builder
22
USER 0
33

44
ARG BUILD_FLAVOR="default"
5+
ARG MESA_VERSION=24.2.8-104
56

67
RUN if [[ ${BUILD_FLAVOR} != remoting ]]; then \
78
dnf install -y python3-dnf-plugin-versionlock && \
89
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm && \
910
dnf copr enable -y slp/mesa-krunkit epel-9-aarch64 && \
10-
dnf install -y mesa-vulkan-drivers-24.1.2-101.el9.aarch64 && \
11-
dnf versionlock mesa-vulkan-drivers-24.1.2-101.el9.aarch64 && \
11+
dnf install -y mesa-vulkan-drivers-${MESA_VERSION}.el9.aarch64 && \
12+
dnf versionlock mesa-vulkan-drivers-${MESA_VERSION}.el9.aarch64 && \
1213
dnf install -y git cmake gcc gcc-c++ vulkan-loader-devel vulkan-tools fmt-devel && \
1314
dnf copr enable -y jeffmaury/shaderc epel-9-aarch64 && \
1415
dnf install -y glslc && \

projects/mac_ai/testing/podman.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import pathlib
33
import logging
4+
import yaml
45

56
from projects.core.library import env, config, run, configure_logging, export
67
import remote_access, utils
@@ -214,3 +215,19 @@ def get_exec_command_prefix():
214215
podman_cmd = get_podman_command()
215216

216217
return f"{podman_cmd} exec -it {container_name}"
218+
219+
220+
def login(base_work_dir, credentials_key):
221+
creds_str = config.project.get_config(credentials_key, handled_secretly=True)
222+
creds = yaml.safe_load(creds_str)
223+
podman_bin = get_podman_binary(base_work_dir)
224+
225+
cmd = f"{podman_bin} login --username '{creds['login']}' --password '{creds['password']}' '{creds['server']}'"
226+
remote_access.run_with_ansible_ssh_conf(base_work_dir, cmd, handled_secretly=True)
227+
228+
229+
def push_image(base_work_dir, local_name, remote_name):
230+
podman_bin = get_podman_binary(base_work_dir)
231+
cmd = f"{podman_bin} push {local_name} {remote_name}"
232+
233+
remote_access.run_with_ansible_ssh_conf(base_work_dir, cmd)

projects/mac_ai/testing/podman_machine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def start(base_work_dir, use_remoting=None):
5656

5757
ret = _run(base_work_dir, f"start {name}", env, print_cmd=True)
5858

59-
if config.project.get_config("prepare.podman.machine.remoting_env.enabled"):
59+
if use_remoting and config.project.get_config("prepare.podman.machine.remoting_env.enabled"):
6060
if not config.project.get_config("prepare.virglrenderer.enabled"):
6161
logging.warning("The custom virglrenderer isn't enabled ...")
6262

projects/mac_ai/testing/prepare_llama_cpp.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -156,40 +156,47 @@ def prepare_from_release(base_work_dir, platform):
156156
return llama_cpp_path
157157

158158

159-
def prepare_from_source(base_work_dir, platform):
160-
version = config.project.get_config("prepare.llama_cpp.source.repo.version")
161-
159+
def get_source_dir(base_work_dir):
160+
version = config.project.get_config("prepare.llama_cpp.source.repo.version", print=False)
162161
dirname = "llama.cpp-"
163162
if version.startswith("pr-"):
164163
dirname += version
165164
else:
166165
dirname += f"tag-{version}"
167166

168-
dest = base_work_dir / "llama_cpp" / dirname
167+
return base_work_dir / "llama_cpp" / dirname
169168

170-
if not remote_access.exists(dest):
171-
repo_url = config.project.get_config("prepare.llama_cpp.source.repo.url")
172169

173-
kwargs = dict(
174-
repo_url=repo_url,
175-
dest=dest,
176-
)
170+
def prepare_from_source(base_work_dir, platform):
171+
version = config.project.get_config("prepare.llama_cpp.source.repo.version")
177172

178-
if version.startswith("pr-"):
179-
pr_number = version.removeprefix("pr-")
180-
kwargs["refspec"] = f"refs/pull/{pr_number}/head"
181-
else:
182-
kwargs["version"] = version
173+
dest = get_source_dir(base_work_dir)
183174

184-
run.run_toolbox(
185-
"remote", "clone",
186-
**kwargs,
187-
artifact_dir_suffix="_llama_cpp",
188-
)
175+
# don't check if already exists, always build it
176+
177+
repo_url = config.project.get_config("prepare.llama_cpp.source.repo.url")
178+
179+
kwargs = dict(
180+
repo_url=repo_url,
181+
dest=dest,
182+
)
183+
184+
if version.startswith("pr-"):
185+
pr_number = version.removeprefix("pr-")
186+
kwargs["refspec"] = f"refs/pull/{pr_number}/head"
187+
else:
188+
kwargs["version"] = version
189+
190+
run.run_toolbox(
191+
"remote", "clone",
192+
**kwargs,
193+
force=True,
194+
artifact_dir_suffix="_llama_cpp",
195+
)
189196

190-
# for the Kompute build
191-
cmd = f"sed -i.bu s/-Werror//g {dest}/ggml/src/ggml-kompute/kompute/CMakeLists.txt"
192-
remote_access.run_with_ansible_ssh_conf(base_work_dir, cmd)
197+
# for the Kompute build
198+
cmd = f"sed -i.bu s/-Werror//g {dest}/ggml/src/ggml-kompute/kompute/CMakeLists.txt"
199+
remote_access.run_with_ansible_ssh_conf(base_work_dir, cmd)
193200

194201
src_dir = dest
195202
cmake_parallel = config.project.get_config("prepare.llama_cpp.source.cmake.parallel")

projects/mac_ai/testing/prepare_mac_ai.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from projects.core.library import env, config, run, configure_logging, export
66
from projects.matrix_benchmarking.library import visualize
77

8-
import prepare_llama_cpp, utils, remote_access, podman_machine, brew, podman, prepare_virglrenderer
9-
import llama_cpp, ollama, ramalama
8+
import utils, remote_access, podman_machine, brew, podman, prepare_virglrenderer, prepare_release
9+
import prepare_llama_cpp, llama_cpp, ollama, ramalama
1010

1111
TESTING_THIS_DIR = pathlib.Path(__file__).absolute().parent
1212
CRC_MAC_AI_SECRET_PATH = pathlib.Path(os.environ.get("CRC_MAC_AI_SECRET_PATH", "/env/CRC_MAC_AI_SECRET_PATH/not_set"))
@@ -26,6 +26,7 @@
2626

2727
REMOTING_FRONTEND_PLATFORM = "podman/llama_cpp/remoting"
2828
REMOTING_BACKEND_PLATFORM = "macos/llama_cpp/remoting"
29+
RAMALAMA_REMOTING_PLATFORM = "podman/ramalama/remoting"
2930

3031
def cleanup():
3132
base_work_dir = remote_access.prepare()
@@ -92,7 +93,10 @@ def cleanup():
9293

9394
def prepare():
9495
base_work_dir = remote_access.prepare()
96+
9597
if not config.project.get_config("prepare.prepare_only_inference_server"):
98+
run.run_toolbox("mac_ai", "remote_capture_system_state")
99+
96100
if config.project.get_config("prepare.podman.repo.enabled"):
97101
podman.prepare_from_gh_binary(base_work_dir)
98102
podman.prepare_gv_from_gh_binary(base_work_dir)
@@ -173,6 +177,16 @@ def prepare_binary():
173177
if config.project.get_config("prepare.podman.machine.enabled"):
174178
podman_machine.configure_and_start(base_work_dir, force_restart=False)
175179

180+
if config.project.get_config("prepare.remoting.publish"):
181+
if config.project.get_config("exec_list.pre_cleanup_ci") is False:
182+
raise ValueError("Cannot publish the remoting libraries if not preparing from a clean environment")
183+
if not config.project.get_config("prepare.virglrenderer.enabled"):
184+
raise ValueError("Cannot publish the remoting libraries if building virglrenderer isn't enabled")
185+
if "podman/llama_cpp/remoting" not in platforms_to_build_str:
186+
raise ValueError("Cannot publish the remoting libraries if podman/llama_cpp/remoting isn't built")
187+
188+
prepare_release.create_remoting_tarball(base_work_dir)
189+
176190
return 0
177191

178192

0 commit comments

Comments
 (0)