Skip to content

Apple M4 Silicon with GPU compatability #52

Open
@sverze

Description

@sverze

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions