AI Sparkup

최신 AI 쉽게 깊게 따라잡기⚡

ZML – Zig 기반 크로스 하드웨어 ML 추론 프레임워크

ZML은 “Any model. Any hardware. Zero compromise.”를 표방하는 오픈소스 ML 추론 프레임워크다. Zig 언어로 작성되고 Google의 OpenXLA·MLIR 컴파일러 스택과 Bazel 빌드 시스템을 기반으로 하며, NVIDIA CUDA·AMD ROCm·Google TPU·AWS Trainium/Inferentia 등 다양한 하드웨어 백엔드를 단일 코드베이스에서 지원한다. GitHub 스타 3,600개(2026년 6월 기준)를 보유한 주목받는 프로젝트다.

왜 주목받는가

기존 ML 추론 프레임워크들은 특정 하드웨어(CUDA)나 특정 언어(Python)에 강하게 종속되는 경우가 많다. ZML은 Zig의 낮은 오버헤드와 OpenXLA의 크로스 플랫폼 컴파일 능력을 결합해 프로덕션 환경에서 하드웨어 종속성 없이 고성능 추론을 달성한다.

지원 하드웨어

Bazel 빌드 플래그로 타깃 하드웨어를 지정한다:

하드웨어플래그
NVIDIA CUDA--@zml//platforms:cuda=true
AMD ROCm--@zml//platforms:rocm=true
Google TPU--@zml//platforms:tpu=true
AWS Trainium / Inferentia 2--@zml//platforms:neuron=true
CPU (비활성화)--@zml//platforms:cpu=false

빠른 시작

LLM 실행

현재 공식 지원 모델: Llama 3.1/3.2, Qwen 3.5, LFM 2.5

# HuggingFace에서 모델 로드 후 즉시 실행
bazel run //examples/llm -- \
  --model=hf://meta-llama/Llama-3.2-1B-Instruct \
  --prompt="Write a haiku about Zig"

# 대화형 채팅 루프 (--prompt 생략)
bazel run //examples/llm -- \
  --model=hf://meta-llama/Llama-3.2-1B-Instruct

# CUDA GPU에서 실행
bazel run //examples/llm --@zml//platforms:cuda=true -- \
  --model=hf://meta-llama/Llama-3.2-1B-Instruct \
  --prompt="What is the capital of France?"

HuggingFace 게이팅 모델(Meta Llama 등)은 먼저 인증이 필요하다:

bazel run //tools/hf -- auth login
# 또는 HF_TOKEN 환경변수 설정

모델 소스

  • HuggingFace: --model=hf://org/repo
  • 로컬 디렉터리: --model=/var/models/meta-llama/Llama-3.2-1B-Instruct
  • S3: --model=s3://bucket/path/to/model

ZML 핵심 개념

ZML은 Zig 구조체로 모델을 정의하고, zml.Tensor 타입으로 연산을 기술한다. 아래는 2레이어 MNIST 모델 예시:

const Layer = struct {
    weight: zml.Tensor,
    bias: zml.Tensor,

    pub fn forward(self: Layer, input: zml.Tensor) zml.Tensor {
        return self.weight.dot(input, .d).add(self.bias).relu().withTags(.{.d});
    }
};

핵심 개념:

  • Tensor: 연산의 기본 단위
  • Model: Zig 구조체로 정의되는 모델
  • Executable: 컴파일된 실행 가능 모델 (XLA/MLIR 기반)

사용 대상

사용자시나리오
ML 인프라 엔지니어하드웨어 의존도 없는 프로덕션 추론 서버 구축
시스템 프로그래머Zig 생태계에서 ML 모델 통합
연구자다양한 하드웨어 백엔드에서 모델 성능 비교

라이선스 및 링크



AI Sparkup 구독하기

최신 게시물 요약과 더 심층적인 정보를 이메일로 받아 보세요! (무료)