Skip to content

Apple M4 Silicon with GPU compatability #52

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

Open
sverze opened this issue Feb 23, 2025 · 1 comment
Open

Apple M4 Silicon with GPU compatability #52

sverze opened this issue Feb 23, 2025 · 1 comment

Comments

@sverze
Copy link

sverze commented Feb 23, 2025

I thought I might try and get the Docker GPU image working on my M4 with GPU.
Changes are needed to switch from NVIDIA to Tensorflow.

Warp/Claude suggested changes are below, but before I embark on this mission, has anyone tried this and is it achievable or worth it?

Suggested changes:

After reviewing your docker-compose.gpu.yml file, there are several changes needed to make it work on your M4 MacBook Pro with Metal GPU support:

  1. Remove the NVIDIA-specific configuration:
version: '3'

services:
  app:
    build:
      context: .
      dockerfile: ./docker/Dockerfile.gpu
    platform: linux/arm64
    tty: true
    volumes:
      - ./data/:/app/data
      - ./notebooks/:/app/notebooks
      - ./scripts/:/app/scripts
    ports:
      - "$JUPYTER_PORT:$JUPYTER_PORT"
      - "$TENSORBOARD_PORT:$TENSORBOARD_PORT"
    env_file:
      - ./.env
    entrypoint: jupyter lab --ip ******* --port=$JUPYTER_PORT --no-browser --allow-root
  1. Replace the current Dockerfile.gpu with this Metal-compatible version:
# Use Python base image for ARM64
FROM --platform=linux/arm64 python:3.9-slim

# System dependencies
RUN apt-get update && apt-get install -y \
    unzip \
    graphviz \
    curl \
    musescore3 \
    && rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade pip

WORKDIR /app

# Install TensorFlow for Mac (Metal GPU support)
RUN pip install tensorflow-macos tensorflow-metal

COPY ./requirements.txt /app

# Modify your requirements.txt installation
# Remove tensorflow if it's in requirements.txt since we installed tensorflow-macos
RUN grep -v "tensorflow" requirements.txt > requirements_filtered.txt && \
    pip install -r requirements_filtered.txt

COPY /notebooks/. /app/notebooks
COPY /scripts/. /app/scripts

ENV PYTHONPATH="${PYTHONPATH}:/app"
  1. Update the requirement.txt file to use macos tensorflow libraries:
# Core ML Libraries
tensorflow-macos>=2.10.0   # Apple Silicon specific TensorFlow
tensorflow-metal>=0.7.0    # Metal GPU acceleration support
tensorflow-probability==0.18.0  # Keep same version for compatibility

# Scientific Computing
matplotlib==3.6.3
scipy==1.10.0
scikit-learn==1.2.1
scikit-image==0.19.3
pandas==1.5.3

# Development Tools
jupyterlab==3.5.3
black[jupyter]==23.1.0
click==8.0.4
flake8==5.0.4
flake8-nb==0.5.2
ipywidgets==8.0.4

# Domain Specific
music21==8.1.0
kaggle==1.5.12
pydot==1.4.2

Important Notes:

  1. This setup uses TensorFlow-Metal, which is specifically designed for Apple Silicon.
  2. You might experience some compatibility issues with certain TensorFlow operations or models, as not all features are fully supported on Metal yet.
  3. The performance characteristics might differ from NVIDIA GPU implementations.

Alternative Recommendation:
Given that you're running on Apple Silicon, you might want to consider running your ML workload directly on the host machine instead of using Docker. This would give you better performance and direct access to the Metal GPU. You could:

  1. Use miniforge to create a conda environment
  2. Install tensorflow-macos and tensorflow-metal directly
  3. Run your notebooks locally
@dev-alabdallamh
Copy link

dev-alabdallamh commented Mar 7, 2025

My machine is MacBook Pro M4 MAX Chip

I tried these steps above and got this error
regarding what it was saying I tried to fix but no luck

[app 6/8] RUN pip install -r /app/requirements.txt:
0.271 ERROR: Could not find a version that satisfies the requirement tensorflow-macos>=2.10.0 (from versions: none)
0.285 ERROR: No matching distribution found for tensorflow-macos>=2.10.0


failed to solve: process "/bin/sh -c pip install -r /app/requirements.txt" did not complete successfully: exit code: 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants