thisisthepy
Ecosystem생태계 / Projects프로젝트 / torchnative
Language and runtime

torchnative

PyTorch-style models on devices without PyTorch: a Rust runtime behind the API people already use.PyTorch가 없는 기기에서 PyTorch 방식의 모델을: 사람들이 이미 쓰는 API 뒤에 Rust 런타임을 둡니다.

GitHub · Guide

Overview개요

torchnative runs the models people already use, through the API they already use, on devices where PyTorch does not exist. Python calls from_pretrained, generate and familiar tensor operations; a runtime written in Rust executes them on CPU, Apple Metal, Vulkan and neural processing units.

torchnative는 사람들이 이미 쓰는 모델을, 이미 쓰는 API로, PyTorch가 없는 기기에서 돌립니다. Python은 from_pretrained, generate, 익숙한 텐서 연산을 부르고, Rust로 쓴 런타임이 CPU, Apple Metal, Vulkan, 신경망 처리 장치에서 실행합니다.

The problem it solves푸는 문제

A model that works in a notebook usually has to be converted to another format, rewritten for another runtime or moved behind a server before it can run in an app. Each step loses fidelity, tooling or privacy, and PyTorch itself is too large for most devices and absent on many.

노트북에서 도는 모델을 앱에서 돌리려면 보통 다른 형식으로 변환하거나, 다른 런타임용으로 다시 쓰거나, 서버 뒤로 옮겨야 합니다. 단계마다 정확도, 도구, 사생활 중 무언가를 잃고, PyTorch 자체는 대부분의 기기에 너무 크고 많은 기기에는 아예 없습니다.

How it works동작 방식

  • API shape. The torch and transformers surfaces Python code imports, so loading, tokenising, generating and streaming look the same as in a notebook.
  • Runtime. torch_c, a Rust core with kernels for CPU, Metal and Vulkan, quantised weight formats, and an autograd tape for training.
  • Serving. Continuous batching of many requests on one engine, the basis of Gemstone's server.
  • Agreement. Results are checked against upstream PyTorch on the CPU, model by model.
  • API 모양. Python 코드가 import하는 torch와 transformers 표면 그대로라서 로딩, 토큰화, 생성, 스트리밍이 노트북과 같아 보입니다.
  • 런타임. CPU, Metal, Vulkan 커널, 양자화 가중치 형식, 학습용 autograd 테이프를 가진 Rust 코어 torch_c.
  • 서빙. 엔진 하나에서 여러 요청을 연속 배칭하며, Gemstone 서버의 바탕입니다.
  • 일치. 결과는 모델마다 CPU에서 원래 PyTorch와 대조합니다.

Design decisions설계 결정

  • Keep the API, replace what is underneath. Users do not port their code.
  • Devices as first-class targets, NPUs included, in the same from_pretrained and generate shape.
  • Built by pypackpack. The package is laid out as a pypackpack package: torchnative/python and torchnative/rust.
  • API는 두고 아래를 바꾼다. 사용자는 코드를 옮기지 않습니다.
  • 기기가 일급 타깃. NPU까지 같은 from_pretrained와 generate 모양으로.
  • pypackpack으로 빌드. 패키지는 pypackpack 패키지 구조입니다. torchnative/python과 torchnative/rust.

Where it fits생태계 안의 위치

Inside an app it runs on the CPython embedded by python-multiplatform. Gemstone's engine is its first production user. pypackpack's Cargo backend will build its Rust core for every target.

앱 안에서는 python-multiplatform이 넣은 CPython 위에서 돕니다. Gemstone 엔진이 첫 실사용자입니다. pypackpack의 Cargo 백엔드가 Rust 코어를 모든 타깃용으로 빌드하게 됩니다.

Where it stands현재 상태

Working: Qwen3 agreement with upstream, plain and 8-bit streaming, continuous batching on CPU, bfloat16. In progress: repository layout, generation on Metal, automated releases.

동작: Qwen3 원본과 일치, 일반과 8비트 스트리밍, CPU 연속 배칭, bfloat16. 진행 중: 저장소 구조, Metal에서의 생성, 자동 배포.

Future design미래 설계

  • Free-threaded wheels for CPython 3.15t, so inference runs in a free-threaded app without turning the GIL back on.
  • 4-bit weights, faster paged attention, more model families and continuous batching on Metal.
  • On-device inference inside Gemstone's app.
  • CPython 3.15t용 free-threaded wheel. free-threaded 앱에서 GIL을 다시 켜지 않고 추론합니다.
  • 4비트 가중치, 더 빠른 paged attention, 더 많은 모델 계열, Metal 연속 배칭.
  • Gemstone 앱 안의 온디바이스 추론.

Roadmap로드맵

  1. 0.1.0b5, 2026-10-24: layout, Metal generation, releases.
  2. M2, 2026-11-13: batching and fixes on Metal.
  3. M2b, 2026-11-27: 4-bit quantisation, larger Qwen3 models.
  1. 0.1.0b5, 2026-10-24: 구조, Metal 생성, 배포.
  2. M2, 2026-11-13: Metal 배칭과 수정.
  3. M2b, 2026-11-27: 4비트 양자화, 더 큰 Qwen3 모델.