C.W.K.
Stream
Lesson 05 of 06 · published

MLX vs PyTorch MPS vs CoreML — 셋이서 솔직히

~16 min · comparison, pytorch-mps, coreml

Level 0Curious
0 XP0/51 lessons0/15 achievements
0/100 XP to next level100 XP to go0% complete

Framework 셋, 서로 다른 일 셋

이게 우리가 calibrate 하는 레슨이야. MLX Quest 의 대부분은 필요상 MLX-긍정 — 그걸 가르치고 있으니까. 근데 MLX 는 Apple Silicon 위에 같이 사는 다른 두 ML stack 이 있는 진짜 ecosystem 안에 존재하고, 셋을 혼동하면 시간 잡아먹어. 솔직한 stack-up 여기.

  • MLX — Apple 의 연구 지향 array framework, Python-first, unified memory 에 native.
  • PyTorch 의 MPS backend — PyTorch 의 CUDA-shape API 가 기존 PyTorch 코드가 Mac 에서 돌게 Metal 호출로 번역된 것.
  • CoreML — Apple 의 앱 출하용 ML runtime, Swift-first, 사전 학습된 모델을 iOS / macOS / watchOS / tvOS 앱 안에 박게 박힌 거.

각각의 모양

PyTorch MPS 는 통역사. 목표는 "CUDA 용으로 박힌 PyTorch 코드가 가능한 한 적은 변경으로 Mac 에서 돈다." 네가 아는 같은 torch.tensor 객체 쓰고, device='cuda:0' 대신 device='mps' 받아. MPS backend 가 각 PyTorch op 을 Metal Performance Shader 호출로 번역. 로컬에서 이터레이트 하고 싶은 기존 PyTorch codebase 가 있을 때 좋아. Native Apple-Silicon-shape API 원할 때는 안 좋아 — GPU 가 자체 메모리 가진 별도 device 인 CUDA 세계관을 물려받으니까.

MLX 가 원어민. API 가 unified-memory 하드웨어 (lesson 2) 모양으로 박혔어. Mental model 이 복사 없이 CPU 와 GPU 작업할 수 있다고, lazy graph 가 정상이라고, function transform 이 first-class 라고 가정. Apple Silicon 위에 새로 시작할 때 좋아. MLX 등가물 없는 50 개의 CUDA-specific op 쓰는 기존 PyTorch 모델 돌려야 할 때는 안 좋아.

CoreML 이 runtime. 학습된 모델 (PyTorch, TensorFlow, 무엇이든) 을 .mlpackage 로 변환하고 앱 안에 박아. Runtime 이 모델 로드, 추론, 그리고 (중요하게) 디바이스 위 배포 보장 — App Store 배포, on-device privacy, Vision 과 Speech framework 와의 통합 — 처리. 앱 안의 feature 출하할 때 좋아. 연구하거나, 앱 릴리스와 독립으로 모델 업데이트하고 싶을 때는 안 좋아.

같은 matrix multiply, 셋의 방식

아래는 MLX 와 PyTorch MPS 의 등가 코드. 둘 다 같은 `mlx` env 에서 검증 (마침 torch 도 깔려 있어서 MPS 동작). CoreML 은 보여줄 가치 있는 Python 레벨 matmul 스니펫이 없어 — 그 Python 면은 모델 변환용이지, array 수학용이 아냐.

의사결정 나무

  • Apple Silicon 위에서 연구 / 새 프로젝트 → MLX. 원어민이 통역사 이김.
  • 기존 PyTorch codebase, Mac 에서 개발하고 싶음 → PyTorch MPS. 재작성 적음. MPS coverage 갭은 가면서 발견할 거.
  • iOS / macOS / watchOS / tvOS 앱 안에 모델 출하 → CoreML. App Store 배포, privacy 보장, OS 레벨 통합이 중요.
  • HTTP endpoint 로 LLM 을 로컬에 서빙 → MLX (구체적으로 mlx-lm — Track 2 봐).
  • 그냥 Python 안 쓰고 "뜨거운 모델, 군더더기 없음" → Ollama (v0.19 부터 MLX 위에 빌드 — compare.lesson1 봐).

이 레슨이 안 말하는 것

나는 MLX 가 모든 벤치마크에서 PyTorch MPS 보다 빠르다고 안 말해 — 어떤 땐 MPS 가 이기고, 어떤 땐 MLX 가 이기고, 리더는 MLX 릴리스 사이에 바뀌어. 나는 framework 들이 다른 일에 모양이 박혔다고 말해. 일로 골라, 부족으로 고르지 말고.

Code

MLX 의 같은 matmul·python
import mlx.core as mx

x = mx.random.normal((1024, 1024))
y = x @ x.T
mx.eval(y)
print("MLX     :", tuple(y.shape), y.dtype, mx.default_device())

# Verified output (2026-05-03):
#   MLX     : (1024, 1024) mlx.core.float32 Device(gpu, 0)
PyTorch MPS backend 의 같은 matmul·python
# Requires PyTorch ≥ 2.0 with MPS support and macOS ≥ 12.3.
import torch

device = torch.device("mps" if torch.backends.mps.is_available() else "cpu")
x = torch.randn(1024, 1024, device=device)
y = x @ x.T
print("PyTorch :", tuple(y.shape), y.dtype, y.device)

# Verified output (2026-05-03, torch 2.11.0):
#   PyTorch : (1024, 1024) torch.float32 mps:0
CoreML 모델 변환 (스케치 — Swift 가 배포 면)·python
# CoreML's Python surface is the conversion side, not array math.
# A typical workflow is: train in PyTorch, export to ONNX, convert to .mlpackage,
# then embed in a Swift app. Sketch only — not for execution here.
import coremltools as ct
import torch

# Suppose you have a trained PyTorch model `model` ...
# example_input = torch.rand(1, 3, 224, 224)
# traced = torch.jit.trace(model.eval(), example_input)
# mlmodel = ct.convert(
#     traced,
#     inputs=[ct.TensorType(shape=example_input.shape)],
#     compute_units=ct.ComputeUnit.ALL,   # CPU + GPU + Neural Engine
# )
# mlmodel.save("MyModel.mlpackage")

External links

Exercise

MLX 와 PyTorch MPS matmul 코드 블록 둘 다 돌려 (두 번째는 env 에 torch 깔려 있어야 동작 — 안 깔려 있으면 pip install torch, 근데 mlx env 깨끗하게 유지하고 싶으면 별도 env 에). 4096×4096 matmul 을 python -c 'import time; ...' 로 timing, 각 세 번 돌려 중앙값 잡아. 포인트는 *승자 선언* 이 아냐 — timing variance 느끼고, 답이 shape, dtype, 어느 framework 가 마지막에 릴리스했는지에 달려 있다는 거 알아채는 거. 뭘 알아챘는지 두 문장.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.