Skip to content

Commit

Permalink
macos fail
Browse files Browse the repository at this point in the history
  • Loading branch information
aturker-synnada committed Jan 6, 2025
1 parent 43b5569 commit 5a231d8
Show file tree
Hide file tree
Showing 4 changed files with 297 additions and 26 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/ci-test-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:
CI: true
jobs:
build:
runs-on: macos-15-xlarge
runs-on: macos-14
strategy:
matrix:
python-version: [3.12]
Expand All @@ -33,14 +33,9 @@ jobs:
pip install --upgrade "jax[cpu]"
pip install mlx
pip install -r requirements/dev.txt
- name: Run pre-commit
run: |
python3 -m pip install mypy
python3 -m pip install pre-commit
pre-commit run --all-files
python3 license_checker.py
pip install psutil
- name: Execute testcase unit tests
run: pytest --cov --cov-report=xml -s tests/
run: python3 script.py
- name: Upload results to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
145 changes: 145 additions & 0 deletions script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Copyright 2022 Synnada, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import datetime
import platform
import subprocess

import psutil

# testing_fns: dict[type[ml.Backend], Callable] = {}
# array_fns: dict[type[ml.Backend], Callable] = {}


try:
import jax.numpy as jnp
import numpy as np

lambda x, y, rtol, atol: np.allclose(
x.astype(jnp.float64), y.astype(jnp.float64), atol=atol, rtol=rtol
)


except ImportError:
pass


def get_processor_details():
try:
# Run sysctl command to get CPU brand string
result = subprocess.run(
["sysctl", "-n", "machdep.cpu.brand_string"], capture_output=True, text=True
)

# Check if running on Apple Silicon
if platform.processor() == "arm":
# Get detailed chip information
chip_info = subprocess.run(
["sysctl", "-n", "machdep.cpu.brand_string"],
capture_output=True,
text=True,
).stdout.strip()

# Alternative way to get chip info if above doesn't work
if not chip_info:
system_profiler = subprocess.run(
["system_profiler", "SPHardwareDataType"],
capture_output=True,
text=True,
)
for line in system_profiler.stdout.split("\n"):
if "Chip" in line or "Processor" in line:
chip_info = line.split(":")[-1].strip()
break

return f"Apple {chip_info}"
else:
return result.stdout.strip()
except Exception:
return platform.processor()


def get_macos_info():
# Basic system information
print("\n=== System Information ===")
print(f"OS: {platform.system()} {platform.mac_ver()[0]}")
print(f"Computer Name: {platform.node()}")
print(f"Architecture: {platform.machine()}")

# Detailed processor information
processor_info = get_processor_details()
print(f"Processor: {processor_info}")

# Memory information
mem = psutil.virtual_memory()
print("\n=== Memory Information ===")
print(f"Total Memory: {mem.total / (1024**3):.2f} GB")
print(f"Available Memory: {mem.available / (1024**3):.2f} GB")
print(f"Memory Usage: {mem.percent}%")

# Detailed chip information from system_profiler
try:
print("\n=== Detailed Chip Information ===")
system_profiler = subprocess.run(
["system_profiler", "SPHardwareDataType"], capture_output=True, text=True
)
for line in system_profiler.stdout.split("\n"):
if any(
keyword in line
for keyword in ["Chip:", "Processor:", "Memory:", "Neural"]
):
print(line.strip())
except Exception:
pass

# CPU information
print("\n=== CPU Information ===")
print(f"CPU Cores (Physical): {psutil.cpu_count(logical=False)}")
print(f"CPU Cores (Logical): {psutil.cpu_count(logical=True)}")
print(f"CPU Usage: {psutil.cpu_percent(interval=1)}%")

# Battery information (if available)
if hasattr(psutil, "sensors_battery"):
battery = psutil.sensors_battery()
if battery:
print("\n=== Battery Information ===")
print(f"Battery Percentage: {battery.percent}%")
print(f"Power Plugged In: {'Yes' if battery.power_plugged else 'No'}")

# Boot time
boot_time = datetime.datetime.fromtimestamp(psutil.boot_time())
print("\n=== System Uptime ===")
print(f"Last Boot: {boot_time.strftime('%Y-%m-%d %H:%M:%S')}")


def test_info():
print("test_info")
get_macos_info()
print("test_info done")


def test_first():
print("test_first")
test_info()
x = jnp.array([1, 2, 3], dtype=jnp.bfloat16)
y = jnp.array([1.0, 2, 3], dtype=jnp.bfloat16)
print("x", x)
print("y", y)
jnp.allclose(x, y, 1e-5, 1e-5)

print("test_first done")


if __name__ == "__main__":
test_first()
14 changes: 14 additions & 0 deletions tests/scripts/test_all_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,20 @@ def compile_and_compare(
# Primitive Model Tests


def test_jax():
arr = [1.0, 2.0, 3.0]
backends = [
JaxBackend(dtype=mithril.float16),
JaxBackend(dtype=mithril.float32),
JaxBackend(dtype=mithril.float64),
JaxBackend(dtype=mithril.bfloat16),
]
for backend in backends:
print("Jax Backend: ", backend._dtype)
backend.array(arr)
print("Operation is successful!")


def test_buffer_1():
model = Buffer()
compile_kwargs = {
Expand Down
Loading

0 comments on commit 5a231d8

Please sign in to comment.