Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
881ccca
cuda: a process-wide cap on DeviceBuffer and pinned HostBuffer bytes
plotarmordev Oct 16, 2026
b00dd4e
drama: the temporal codebook tower
plotarmordev Oct 16, 2026
c8af505
drama: the speech codec, with codec.pth read without Python
plotarmordev Oct 16, 2026
e192c0f
engine_api: speech requests, speech info and a submit_speech hook
plotarmordev Oct 16, 2026
ab45904
native: Drama 3 (fish_omni) on CUDA
plotarmordev Oct 16, 2026
7553d00
server: POST /v1/audio/speech
plotarmordev Oct 16, 2026
8ba4307
tests: Drama 3 backbone and tower oracles, replays and stage traces
plotarmordev Oct 16, 2026
20249e9
drama: incremental codec decode, bit-identical to the whole decode
plotarmordev Oct 16, 2026
93fcaab
tests: Drama 3 codec oracle, replays and stage trace
plotarmordev Oct 16, 2026
d84284d
engine_api: audio events, so a speech engine can publish PCM while it…
plotarmordev Oct 16, 2026
71c31a9
build: Drama 3 backbone and tower kernels, the drama module, the nati…
plotarmordev Oct 16, 2026
588f1f1
server: stream: true on /v1/audio/speech sends raw PCM chunks as they…
plotarmordev Oct 16, 2026
d8c6a47
drama: the backbone's one-row GEMM stages its weights through shared …
plotarmordev Oct 16, 2026
10796d4
build: the Drama 3 codec kernels and the codec tool steps
plotarmordev Oct 16, 2026
8bc6814
tests: tf-drama-codec-stream-oracle, whole against chunked codec decodes
plotarmordev Oct 16, 2026
40c7c87
core: a direct read the file system refuses goes through the page cache
plotarmordev Oct 16, 2026
23a7fcc
cuda: Module.holds, whether a loaded image defines a device global
plotarmordev Oct 16, 2026
6f85731
drama: the Drama 3 text backbone on CUDA
plotarmordev Oct 16, 2026
05a715f
drama: one-row backbone GEMVs stream weights through a swizzled cp.as…
plotarmordev Oct 16, 2026
9dc8202
drama: add-norm fused with the routed experts' FP8 activation quantiz…
plotarmordev Oct 16, 2026
705541c
drama: one SwiGLU launch for the routed and shared experts
plotarmordev Oct 16, 2026
08291b5
drama: MoE combine on 8-wide vectors
plotarmordev Oct 16, 2026
641b18b
drama: decode attention keeps the next keys' loads in flight
plotarmordev Oct 16, 2026
01b7f3b
drama: the tower's one decode row attends as a thread-block cluster
plotarmordev Oct 16, 2026
b89dc67
drama: checkpoint weights stream onto the GPU with direct I/O in file…
plotarmordev Oct 16, 2026
0f9345e
speech: a Drama 3 reply that reaches max_frames returns its clipped a…
plotarmordev Oct 16, 2026
9b3934c
drama: one-row attention runs its Q/K norm and RoPE prologue in the s…
plotarmordev Oct 16, 2026
ea06b8b
drama: the tower samples with a stable radix sort
plotarmordev Oct 16, 2026
68aeb3e
drama: the codec builds its weights on its own thread while the backb…
plotarmordev Oct 16, 2026
fdee05c
Merge upstream main (6ee828c2) into feat/drama3-cuda
plotarmordev Oct 17, 2026
0f81a2b
Merge align/920-merge-main (upstream main 6ee828c2) into feat/drama3-…
plotarmordev Oct 17, 2026
15bceca
Merge align/921-merge-main (upstream main 6ee828c2) into fix/drama3-c…
plotarmordev Oct 17, 2026
64e8ff8
Merge align/922-merge-main (upstream main 6ee828c2) into perf/drama3-…
plotarmordev Oct 17, 2026
2d9232a
Merge align/923-merge-main (upstream main 6ee828c2) into perf/drama3-…
plotarmordev Oct 17, 2026
42c548c
Merge align/924-merge-main (upstream main 6ee828c2) into perf/drama3-…
plotarmordev Oct 17, 2026
b56fc8c
drama: below sm_90 the tower's decode row runs drama_attention, and i…
plotarmordev Oct 17, 2026
996637c
Merge align/924-merge-main into perf/drama3-load: the tower's sm_90 c…
plotarmordev Oct 17, 2026
65cd256
engine_api and native/cuda.zig back under 600 lines: speech and visio…
plotarmordev Oct 17, 2026
f5aa7a5
Merge align/920-merge-main into feat/drama3-streaming: speech and vis…
plotarmordev Oct 17, 2026
fd87532
Merge align/921-merge-main into fix/drama3-clipped-replies: speech an…
plotarmordev Oct 17, 2026
572afe3
Merge align/922-merge-main into perf/drama3-backbone-one-row: speech …
plotarmordev Oct 17, 2026
1ecf53b
Merge align/923-merge-main into perf/drama3-tower-decode: speech and …
plotarmordev Oct 17, 2026
bd11ba4
Merge align/924-merge-main into perf/drama3-load: speech and vision t…
plotarmordev Oct 17, 2026
118086a
core: lane tests ignore the speech audio event
plotarmordev Oct 17, 2026
4d41f5a
Merge align/921-merge-main into fix/drama3-clipped-replies: lane test…
plotarmordev Oct 17, 2026
2b27b19
Merge align/922-merge-main into perf/drama3-backbone-one-row: lane te…
plotarmordev Oct 17, 2026
e45d71b
Merge align/923-merge-main into perf/drama3-tower-decode: lane tests …
plotarmordev Oct 17, 2026
809e103
Merge align/924-merge-main into perf/drama3-load: lane tests ignore t…
plotarmordev Oct 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 15 additions & 89 deletions zig/src/core/engine_api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -109,94 +109,6 @@ pub const Request = struct {
}
};

/// Mono PCM written before a successful speech request's finished event.
pub const SpeechResult = struct { samples: usize = 0 };

/// Caller-owned until finished, even on cancellation; a streamed request's pcm[0..n] is the caller's after ``audio`` n.
pub const SpeechRequest = struct {
prompt: []const u32,
pcm: []f32,
result: *SpeechResult,
seed: u64,
max_frames: u32 = 1024,
temperature: f32 = 1,
top_p: f32 = 0.9,
top_k: u32 = 30,
/// Decode while generating and report each final prefix with ``audio`` events; false: one decode after EOS.
stream: bool = false,
};

pub const SpeechInfo = struct {
sample_rate: u32,
frame_length: u32,
max_frames: u32,
max_prompt_tokens: u32,
};

/// An image prepared for the engine's tower (``Vision.prepare``): patches, patch grid, tokens and a content hash.
pub const PreparedImage = struct { pixels: []f32, gh: u32, gw: u32, tokens: u32, hash: u64 };

/// Image input an engine serves (``Info.vision``): image bytes to tower input, and what a request may hold.
pub const Vision = struct {
ctx: *anyopaque,
/// The image's bytes (any format the platform decodes) at most ``max_tokens`` tokens; allocated in ``a``.
prepare: *const fn (ctx: *anyopaque, a: Allocator, bytes: []const u8, max_tokens: u32) anyerror!PreparedImage,
/// The token the chat template writes once per image, expanded to the image's tokens.
image_token: u32,
/// The tokens the template wraps an image in (the image token among them): text that spells one stays text.
markers: []const u32 = &.{},
/// Tokens the server writes around each image's rows (Nemotron Omni's <img> and </img>); null: the template's own.
wrap: ?[2]u32 = null,
/// Image tokens one request may hold in all, and images.
image_tokens: u32,
max_images: u32,
/// Video input, when the engine's family reads it.
video: ?VideoOffer = null,
/// The engine's words for a prepare error the server cannot word (a decoder library it lacks); null: the server's.
explain: ?*const fn (err: anyerror) ?[]const u8 = null,
};

/// A video's facts as the server's decoder reads them, and its frames on request.
pub const VideoSource = struct {
frames: u64, // the stream's frame count
rate_num: u64, // its average frame rate, num / den
rate_den: u64,
width: u32,
height: u32,
ctx: *anyopaque,
/// The frames at ``indices`` (ascending, distinct), each to ``sink`` in order.
decode: *const fn (ctx: *anyopaque, indices: []const u32, sink: FrameSink) anyerror!void,
};

/// Where a decoded frame goes: RGB rows of ``width`` * 3 bytes, ``stride`` bytes apart.
pub const FrameSink = struct {
ctx: *anyopaque,
take: *const fn (ctx: *anyopaque, k: usize, rgb: []const u8, width: u32, height: u32, stride: usize) anyerror!void,
};

/// A video prepared for the tower: each group of frames an image, and each group's time in seconds.
pub const PreparedVideo = struct { groups: []PreparedImage, times: []f64 };

/// Video input an engine serves (``Vision.video``): how a decoded video becomes images and how the prompt holds them.
pub const VideoOffer = struct {
/// ``src`` at most ``max_tokens`` tokens and ``max_frames`` sampled frames; allocated in ``a``.
prepare: *const fn (ctx: *anyopaque, a: Allocator, src: VideoSource, max_tokens: u32, max_frames: u32) anyerror!PreparedVideo,
/// The token the chat template writes once per video, expanded to its groups.
video_token: u32,
/// The tokens around each group's image tokens; the group's time follows as text.
group_open: u32,
group_close: u32,
/// The tokens the template wraps a video in (the video token among them): text that spells one stays text.
markers: []const u32 = &.{},
/// Video tokens one request may hold in all, videos, and frames sampled a video.
video_tokens: u32,
max_videos: u32,
max_frames: u32,
};

/// --vision: image and video input's limits (``Open.vision``); image_tokens_set: the flag given, over a family default.
pub const VisionOpen = struct { image_tokens: u32 = 4096, image_tokens_set: bool = false, max_images: u32 = 4, video_tokens: u32 = 16384, max_videos: u32 = 2, max_frames: u32 = 256 };

pub const Reason = enum { stop, length, cancelled, failed };

/// What a finished reply's rounds did, for its runtime fields and /metrics.
Expand Down Expand Up @@ -414,7 +326,6 @@ pub const Status = struct {
};

pub const SubmitError = error{ Closed, Busy, InvalidSpans, Unsupported, Stale }; // Stale: a learner's put-back has not reached the device
pub const SpeechSubmitError = error{ Closed, Busy, InvalidRequest, Unsupported };

/// What a reply refused or ended for `Stale` says, a submit's error and a queued job's failure alike.
pub const stale_message = "a Living Weights delete could not be put back on the device: send the delete again to retry it, or restart the server";
Expand Down Expand Up @@ -625,6 +536,21 @@ pub const keepalive = @import("keepalive.zig");
/// A model folder's original files kept before --slide first teaches it, its hold and its rollback (originals.zig).
pub const originals = @import("originals.zig");

/// Image and video input: what an engine offers and what the server prepares for its tower (vision_api.zig).
pub const PreparedImage = @import("vision_api.zig").PreparedImage;
pub const Vision = @import("vision_api.zig").Vision;
pub const VideoSource = @import("vision_api.zig").VideoSource;
pub const FrameSink = @import("vision_api.zig").FrameSink;
pub const PreparedVideo = @import("vision_api.zig").PreparedVideo;
pub const VideoOffer = @import("vision_api.zig").VideoOffer;
pub const VisionOpen = @import("vision_api.zig").VisionOpen;

/// One speech synthesis's request, result, offer and refusals (speech_api.zig).
pub const SpeechRequest = @import("speech_api.zig").Request;
pub const SpeechResult = @import("speech_api.zig").Result;
pub const SpeechInfo = @import("speech_api.zig").Info;
pub const SpeechSubmitError = @import("speech_api.zig").SubmitError;

test {
_ = @import("lane_host.zig");
_ = @import("lane_host_test.zig");
Expand Down
27 changes: 27 additions & 0 deletions zig/src/core/speech_api.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! One speech synthesis: the request, its result, what the engine offers, and why a submit is refused.

/// Mono PCM written before a successful speech request's finished event.
pub const Result = struct { samples: usize = 0 };

/// Caller-owned until finished, even on cancellation; a streamed request's pcm[0..n] is the caller's after ``audio`` n.
pub const Request = struct {
prompt: []const u32,
pcm: []f32,
result: *Result,
seed: u64,
max_frames: u32 = 1024,
temperature: f32 = 1,
top_p: f32 = 0.9,
top_k: u32 = 30,
/// Decode while generating and report each final prefix with ``audio`` events; false: one decode after EOS.
stream: bool = false,
};

pub const Info = struct {
sample_rate: u32,
frame_length: u32,
max_frames: u32,
max_prompt_tokens: u32,
};

pub const SubmitError = error{ Closed, Busy, InvalidRequest, Unsupported };
67 changes: 67 additions & 0 deletions zig/src/core/vision_api.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//! What an engine offers for image and video input, and what the server prepares for its tower.
const std = @import("std");
const Allocator = std.mem.Allocator;

/// An image prepared for the engine's tower (``Vision.prepare``): patches, patch grid, tokens and a content hash.
pub const PreparedImage = struct { pixels: []f32, gh: u32, gw: u32, tokens: u32, hash: u64 };

/// Image input an engine serves (``Info.vision``): image bytes to tower input, and what a request may hold.
pub const Vision = struct {
ctx: *anyopaque,
/// The image's bytes (any format the platform decodes) at most ``max_tokens`` tokens; allocated in ``a``.
prepare: *const fn (ctx: *anyopaque, a: Allocator, bytes: []const u8, max_tokens: u32) anyerror!PreparedImage,
/// The token the chat template writes once per image, expanded to the image's tokens.
image_token: u32,
/// The tokens the template wraps an image in (the image token among them): text that spells one stays text.
markers: []const u32 = &.{},
/// Tokens the server writes around each image's rows (Nemotron Omni's <img> and </img>); null: the template's own.
wrap: ?[2]u32 = null,
/// Image tokens one request may hold in all, and images.
image_tokens: u32,
max_images: u32,
/// Video input, when the engine's family reads it.
video: ?VideoOffer = null,
/// The engine's words for a prepare error the server cannot word (a decoder library it lacks); null: the server's.
explain: ?*const fn (err: anyerror) ?[]const u8 = null,
};

/// A video's facts as the server's decoder reads them, and its frames on request.
pub const VideoSource = struct {
frames: u64, // the stream's frame count
rate_num: u64, // its average frame rate, num / den
rate_den: u64,
width: u32,
height: u32,
ctx: *anyopaque,
/// The frames at ``indices`` (ascending, distinct), each to ``sink`` in order.
decode: *const fn (ctx: *anyopaque, indices: []const u32, sink: FrameSink) anyerror!void,
};

/// Where a decoded frame goes: RGB rows of ``width`` * 3 bytes, ``stride`` bytes apart.
pub const FrameSink = struct {
ctx: *anyopaque,
take: *const fn (ctx: *anyopaque, k: usize, rgb: []const u8, width: u32, height: u32, stride: usize) anyerror!void,
};

/// A video prepared for the tower: each group of frames an image, and each group's time in seconds.
pub const PreparedVideo = struct { groups: []PreparedImage, times: []f64 };

/// Video input an engine serves (``Vision.video``): how a decoded video becomes images and how the prompt holds them.
pub const VideoOffer = struct {
/// ``src`` at most ``max_tokens`` tokens and ``max_frames`` sampled frames; allocated in ``a``.
prepare: *const fn (ctx: *anyopaque, a: Allocator, src: VideoSource, max_tokens: u32, max_frames: u32) anyerror!PreparedVideo,
/// The token the chat template writes once per video, expanded to its groups.
video_token: u32,
/// The tokens around each group's image tokens; the group's time follows as text.
group_open: u32,
group_close: u32,
/// The tokens the template wraps a video in (the video token among them): text that spells one stays text.
markers: []const u32 = &.{},
/// Video tokens one request may hold in all, videos, and frames sampled a video.
video_tokens: u32,
max_videos: u32,
max_frames: u32,
};

/// --vision: image and video input's limits (``Open.vision``); image_tokens_set: the flag given, over a family default.
pub const VisionOpen = struct { image_tokens: u32 = 4096, image_tokens_set: bool = false, max_images: u32 = 4, video_tokens: u32 = 16384, max_videos: u32 = 2, max_frames: u32 = 256 };
15 changes: 2 additions & 13 deletions zig/src/native/cuda.zig
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,15 @@ pub fn open(a: Allocator, gpa: Allocator, io: std.Io, o: api.Open, problem: *[]c
}

fn openDrama(a: Allocator, gpa: Allocator, io: std.Io, o: api.Open, problem: *[]const u8) !?api.Opened {
if (o.tp != 1 or o.rank != 0 or (o.lanes_fixed and o.lanes != 1)) {
problem.* = "Drama 3 serves one synthesis on one CUDA device: use --parallel 1 and no tensor parallelism";
if (refusals.drama(o)) |why| {
problem.* = why;
return null;
}
const window = o.context orelse 8192;
if (window < 1025 or window > 8192) {
problem.* = "Drama 3 supports --context 1025 through 8192";
return null;
}
if (o.slide or o.drafter != null or o.mtp_drafts != null or o.mtp_confidence != null or
(o.prompt_cache_gib != null and o.prompt_cache_gib.? != 0) or
(o.keep != null and o.keep.? != 0) or o.policy.len != 0)
{
problem.* = "Drama 3 does not support learned weights, speculative drafts, retained prompt caches, or text-engine policies";
return null;
}
if (o.vision != null or o.precision != null or o.record != null or o.learn_conversations) {
problem.* = "Drama 3 reads no images or NVFP4 checkpoints and keeps no rows or conversation states: serve it without --vision, --precision, --record and --learn-conversations";
return null;
}
const device = try setting(a, o.device, "TF_CUDA_DEVICE", 0, problem) orelse return null;
const segments = try setting(a, o.segments, "TF_CUDA_SEGMENTS", 1, problem) orelse return null;
if (segments != 1) {
Expand Down
18 changes: 18 additions & 0 deletions zig/src/native/cuda_refusal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ pub fn lfm2(o: api.Open) ?[]const u8 {
const lfm2_vision = "--vision: LFM2 reads the checkpoint's images through its own tower without the flag; " ++
"serve it without --vision";

/// Drama 3 serves one synthesis on one device, without the text engines' extras or flags it does not read.
pub fn drama(o: api.Open) ?[]const u8 {
if (o.tp != 1 or o.rank != 0 or (o.lanes_fixed and o.lanes != 1)) return "Drama 3 serves one synthesis on one CUDA device: use --parallel 1 and no tensor parallelism";
if (o.slide or o.drafter != null or o.mtp_drafts != null or o.mtp_confidence != null or
(o.prompt_cache_gib != null and o.prompt_cache_gib.? != 0) or
(o.keep != null and o.keep.? != 0) or o.policy.len != 0)
return "Drama 3 does not support learned weights, speculative drafts, retained prompt caches, or text-engine policies";
if (o.vision != null or o.precision != null or o.record != null or o.learn_conversations) return "Drama 3 reads no images or NVFP4 checkpoints and keeps no rows or conversation states: serve it without --vision, --precision, --record and --learn-conversations";
return null;
}

/// A family takes --drafter only if it says so, and --learn-conversations only as Nemotron; null: `o` may open `F`.
pub fn family(comptime F: type, o: api.Open) ?[]const u8 {
if (o.drafter != null and !(@hasDecl(F, "takes_drafter") and F.takes_drafter)) return "--drafter loads a separate drafter, and this CUDA family drafts with its own MTP head: serve without --drafter";
Expand Down Expand Up @@ -68,3 +79,10 @@ test "--learn-conversations opens Nemotron only, the one CUDA family whose state
try std.testing.expectStringStartsWith(family(Other, .{ .dir = "d", .model_type = "m", .learn_conversations = true }) orelse "", "--learn-conversations keeps");
try std.testing.expect(family(nemotron.native, .{ .dir = "d", .model_type = "nemotron_h", .learn_conversations = true }) == null);
}

test "Drama 3 refuses tensor parallelism, the text engines' extras and the flags it does not read" {
try std.testing.expect(drama(.{ .dir = "d", .model_type = "fish_omni" }) == null);
try std.testing.expectStringStartsWith(drama(.{ .dir = "d", .model_type = "fish_omni", .tp = 2 }) orelse "", "Drama 3 serves one synthesis");
try std.testing.expectStringStartsWith(drama(.{ .dir = "d", .model_type = "fish_omni", .drafter = "/x" }) orelse "", "Drama 3 does not support");
try std.testing.expectStringStartsWith(drama(.{ .dir = "d", .model_type = "fish_omni", .vision = .{} }) orelse "", "Drama 3 reads no images");
}
Loading