Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- CLI: `tensorfold tfq3 MODEL` pulls, converts and inspects TFQ3 checkpoints for the dedicated families and any Safetensors architecture, encoding natively in Zig when the external `tfq3` GPU binary is not installed; serving paths are unchanged (#5018).

- Tools: the environment-names check passes again after #5408: `LD_AUDIT` and `LD_PRELOAD` are recognised as the prefixes `--confidential` refuses instead of names read nowhere; no engine code changes (#5477). Thanks to @kotevcode.

- Desktop: a ready attachment can start a local or remote conversation without typed text, and folder guidance clears after a successful selection or launch (#4836). Thanks @taylorarndt for the report.
Expand Down
17 changes: 17 additions & 0 deletions docs/quantization.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,20 @@ such as BF16 `[1024, 3, 2, 14, 14]`. It still rejects ranks above five, invalid
overflowing byte counts, and offsets that disagree with tensor size or exceed the data region.
Namespace selection remains available to text loaders that do not interpret a vision tower's layouts.
Reading this metadata does not qualify a vision encoder, checkpoint or device.

## TFQ3 conversion (`tensorfold tfq3`)

`tensorfold tfq3 MODEL` converts a local or Hugging Face Safetensors checkpoint into a cross-platform TFQ3 (3-, 4-, or
5-bit 2D-FWHT vector quantization) directory that loads unmodified on both Apple Silicon Metal and NVIDIA CUDA.

- `MODEL` may be a local checkpoint folder or a Hugging Face repo id (`owner/name[@revision]`); when a repo id is not
yet in the local Hugging Face cache, conversion pulls it with the ordinary authentication and integrity checks,
admitting model types without an inference family. `--no-pull` prevents downloads.
- Known families (`qwen3_5`, `qwen4_exp`, `glm5_next`) dispatch to their dedicated GPU converters when `tfq3`
(`https://github.com/ashhart/TFQ`) is installed; any other Safetensors architecture, or invocations passing
`--bits 3|4|5`, `--target-gib GB`, `--fit auto|GB`, `--quantize-vision`, `--quantize-drafter`, or `--quantize-embed`,
routes to the external model-agnostic converter with mixed-bit budget allocation.
- When the external `tfq3` GPU binary is not installed (or `--native` is passed), conversion is refused because
the experimental native dense layout has no production loader. The direct Zig encoder
API rejects quantized tensors whose rows or columns are not multiples of 128; it does not zero-pad them.
`tensorfold tfq3 inspect DIR` still validates `pw_v3_tables.bin` and every 16 KiB–aligned `.tffpw` shard natively.
5 changes: 4 additions & 1 deletion zig/build/cuda.zig
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ fn qwenVisionModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: s

/// The checkpoint subcommands' module: `models`, `info` and `pull` over the CUDA families.
pub fn checkpointCli(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, strip: ?bool, engines_mod: *std.Build.Module, core: *std.Build.Module) *std.Build.Module {
return b.createModule(.{ .root_source_file = b.path("zig/src/cli/cli.zig"), .target = target, .optimize = optimize, .link_libc = true, .strip = strip, .imports = &.{ .{ .name = "native_engines", .module = engines_mod }, exlr8_build.cliImport(b, target, optimize, core), .{ .name = "core", .module = core } } });
const cli = b.createModule(.{ .root_source_file = b.path("zig/src/cli/cli.zig"), .target = target, .optimize = optimize, .link_libc = true, .strip = strip, .imports = &.{ .{ .name = "native_engines", .module = engines_mod }, exlr8_build.cliImport(b, target, optimize, core), .{ .name = "core", .module = core } } });
const glm_check = engines_mod.import_table.get("glm_cuda") orelse engines_mod.import_table.get("tensorfold") orelse b.createModule(.{ .root_source_file = b.path("zig/src/glm_tfq3_check.zig"), .target = target, .optimize = optimize });
cli.addImport("glm_tfq3_check", glm_check);
return cli;
}

/// `zig build native`: tensorfold-native with the CUDA engines into zig-out/native/bin, as the Metal build makes it.
Expand Down
4 changes: 4 additions & 0 deletions zig/build/cuda_host_more.zig
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ pub fn steps(b: *std.Build, host: std.Build.ResolvedTarget, cuda: *std.Build.Mod
const memory_cli = checkpointCli(b, host, .debug, false, native_modules.engines, mods.core);
memory_cli.root_source_file = b.path("zig/src/cli/tests.zig");
b.step("test-cli-memory-host", "Actual checkpoint info memory tests without device or shader producers").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = memory_cli, .filters = &.{ "info prints family", "issue 934:", "plan" } })).step);
const tfq3_run = b.addRunArtifact(b.addTest(.{ .root_module = memory_cli, .filters = &.{ "tfq3", "KR135" } }));
const conversion_run = b.addRunArtifact(b.addTest(.{ .root_module = memory_cli, .filters = &.{"conversion pull:"} }));
b.step("test-pull-conversion-host", "Conversion config admission and symbolic revision publication without HTTP").dependOn(&conversion_run.step);
b.step("test-tfq3-host", "TFQ3 CLI parsing, native encoding, safety and shard inspection on the host").dependOn(&tfq3_run.step);
b.step("test-info-config", "Info shares the checkpoint config reader and diagnostics").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = memory_cli, .filters = &.{"issue 934:"} })).step);
const cli_run = b.addRunArtifact(b.addTest(.{ .root_module = cli }));
b.step("test-cli-host", "Checkpoint CLI parsing and CUDA start dispatch without devices").dependOn(&cli_run.step);
Expand Down
3 changes: 1 addition & 2 deletions zig/build/dsv41_draft.zig
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ pub fn serverOn(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.b
const api = engine.import_table.get("engine_api").?;
const tokenizer = engine.import_table.get("tokenizer").?;
const template = b.createModule(.{ .root_source_file = b.path("zig/src/core/template/template.zig"), .target = target, .optimize = optimize, .link_libc = true });
const exlr8 = @import("exlr8.zig").cliImport(b, target, optimize, engine.import_table.get("core").?);
const cli = b.createModule(.{ .root_source_file = b.path("zig/src/cli/cli.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{ .{ .name = "native_engines", .module = engine }, .{ .name = "core", .module = engine.import_table.get("core").? }, exlr8 } });
const cli = @import("cuda.zig").checkpointCli(b, target, optimize, null, engine, engine.import_table.get("core").?);
const m = b.createModule(.{
.root_source_file = b.path("zig/src/server/main.zig"),
.target = target,
Expand Down
3 changes: 2 additions & 1 deletion zig/build/hip.zig
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,13 @@ pub fn server(b: *std.Build, target: std.Build.ResolvedTarget, e: Engine, build_
const engines = e.native;
const tokenizer = e.hip.import_table.get("core").?.import_table.get("tokenizer").?;
const template = b.createModule(.{ .root_source_file = b.path("zig/src/core/template/template.zig"), .target = target, .optimize = .ReleaseSafe, .link_libc = true });
const checkpoint_cli = @import("cuda.zig").checkpointCli(b, target, .ReleaseSafe, null, engines, e.hip.import_table.get("core").?);
const exe = b.addExecutable(.{ .name = "tensorfold-native", .root_module = b.createModule(.{
.root_source_file = b.path("zig/src/server/main.zig"),
.target = target,
.optimize = .ReleaseSafe,
.link_libc = true,
.imports = &.{ .{ .name = "core", .module = e.hip.import_table.get("core").? }, .{ .name = "engine_api", .module = api }, .{ .name = "tokenizer", .module = tokenizer }, .{ .name = "template", .module = template }, .{ .name = "native_engines", .module = engines }, .{ .name = "checkpoint_cli", .module = b.createModule(.{ .root_source_file = b.path("zig/src/cli/cli.zig"), .target = target, .optimize = .ReleaseSafe, .link_libc = true, .imports = &.{ .{ .name = "native_engines", .module = engines }, exlr8_build.cliImport(b, target, .ReleaseSafe, e.hip.import_table.get("core").?), .{ .name = "core", .module = e.hip.import_table.get("core").? } } }) } },
.imports = &.{ .{ .name = "core", .module = e.hip.import_table.get("core").? }, .{ .name = "engine_api", .module = api }, .{ .name = "tokenizer", .module = tokenizer }, .{ .name = "template", .module = template }, .{ .name = "native_engines", .module = engines }, .{ .name = "checkpoint_cli", .module = checkpoint_cli } },
}) });
exe.root_module.addOptions("build_options", build_options);
_ = @import("server.zig").addTo(b, exe.root_module, target, .ReleaseSafe);
Expand Down
3 changes: 2 additions & 1 deletion zig/build/metal_server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ pub fn nativeServer(b: *std.Build, target: std.Build.ResolvedTarget, optimize: s
// the HTTP side keeps its safety checks; the engine below it runs at `optimize`
const tokenizer = engines.import_table.get("tokenizer") orelse b.createModule(.{ .root_source_file = b.path("zig/src/core/tokenizer/tokenizer.zig"), .target = target, .optimize = .ReleaseSafe, .link_libc = true });
const template = b.createModule(.{ .root_source_file = b.path("zig/src/core/template/template.zig"), .target = target, .optimize = .ReleaseSafe, .link_libc = true });
const checkpoint_cli = @import("cuda.zig").checkpointCli(b, target, .ReleaseSafe, null, engines, engine);
const exe = b.addExecutable(.{ .name = "tensorfold-native", .root_module = b.createModule(.{
.root_source_file = b.path("zig/src/server/main.zig"),
.target = target,
.optimize = .ReleaseSafe,
.link_libc = true,
.imports = &.{ .{ .name = "core", .module = engine }, .{ .name = "engine_api", .module = api }, .{ .name = "tokenizer", .module = tokenizer }, .{ .name = "template", .module = template }, .{ .name = "native_engines", .module = engines }, .{ .name = "living", .module = living }, .{ .name = "checkpoint_cli", .module = b.createModule(.{ .root_source_file = b.path("zig/src/cli/cli.zig"), .target = target, .optimize = .ReleaseSafe, .link_libc = true, .imports = &.{ .{ .name = "native_engines", .module = engines }, exlr8_build.cliImport(b, target, .ReleaseSafe, engine), .{ .name = "core", .module = engine } } }) } },
.imports = &.{ .{ .name = "core", .module = engine }, .{ .name = "engine_api", .module = api }, .{ .name = "tokenizer", .module = tokenizer }, .{ .name = "template", .module = template }, .{ .name = "native_engines", .module = engines }, .{ .name = "living", .module = living }, .{ .name = "checkpoint_cli", .module = checkpoint_cli } },
}) });
exe.root_module.addOptions("build_options", build_options);
_ = server_build.addTo(b, exe.root_module, target, .ReleaseSafe);
Expand Down
2 changes: 2 additions & 0 deletions zig/build/metal_targets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ pub fn metalTargets(b: *std.Build, target: std.Build.ResolvedTarget, optimize: s
.link_libc = true,
.imports = &.{ .{ .name = "metal", .module = metal }, .{ .name = "tensorfold", .module = engine }, .{ .name = "core", .module = engine }, .{ .name = "cluster", .module = cluster }, .{ .name = "kernel_sources", .module = sources }, .{ .name = "native_engines", .module = engines }, .{ .name = "engine_api", .module = api }, .{ .name = "tokenizer", .module = tokenizer }, exlr8_build.cliImport(b, target, optimize, engine) },
});
if (std.mem.eql(u8, p.name, "tensorfold")) mod.addImport("glm_tfq3_check", engine);
if (p.c_source) |file| {
mod.addCSourceFile(.{ .file = b.path(file), .flags = &.{"-std=c11"} });
}
Expand Down Expand Up @@ -328,6 +329,7 @@ pub fn metalTargets(b: *std.Build, target: std.Build.ResolvedTarget, optimize: s
.link_libc = true,
.imports = &.{ .{ .name = "native_engines", .module = engines }, exlr8_build.cliImport(b, target, optimize, mods.engine), .{ .name = "core", .module = mods.engine } },
}) });
cli_tests.root_module.addImport("glm_tfq3_check", mods.engine);
const run_cli_tests = b.addRunArtifact(cli_tests);
test_step.dependOn(&run_cli_tests.step);
b.step("test-cli", "The checkpoint CLI's host tests").dependOn(&run_cli_tests.step);
Expand Down
2 changes: 1 addition & 1 deletion zig/build/xpu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub fn steps(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.buil
}
const tokenizer = b.createModule(.{ .root_source_file = b.path("zig/src/core/tokenizer/tokenizer.zig"), .target = target, .optimize = .ReleaseSafe, .link_libc = true });
const template = b.createModule(.{ .root_source_file = b.path("zig/src/core/template/template.zig"), .target = target, .optimize = .ReleaseSafe, .link_libc = true });
const checkpoint_cli = b.createModule(.{ .root_source_file = b.path("zig/src/cli/cli.zig"), .target = target, .optimize = .ReleaseSafe, .link_libc = true, .imports = &.{ .{ .name = "native_engines", .module = engines }, exlr8_build.cliImport(b, target, .ReleaseSafe, core), .{ .name = "core", .module = core } } });
const checkpoint_cli = @import("cuda.zig").checkpointCli(b, target, .ReleaseSafe, null, engines, core);
const server = b.addExecutable(.{ .name = "tensorfold-native", .root_module = b.createModule(.{
.root_source_file = b.path("zig/src/server/main.zig"),
.target = target,
Expand Down
10 changes: 8 additions & 2 deletions zig/src/cli/cli.zig
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! The tensorfold checkpoint subcommands (`models`, `info`, `pull`, `rm`, `plan`, `merge`) and `log`.
//! The tensorfold checkpoint subcommands (`models`, `info`, `pull`, `rm`, `plan`, `merge`, `tfq3`) and `log`.
const std = @import("std");
const models = @import("models.zig");
const info = @import("info.zig");
const pull = @import("pull.zig");
const plan = @import("plan.zig");
const pull_exlr8 = @import("pull_exlr8.zig");
const rm = @import("rm.zig");
const tfq3 = @import("tfq3.zig");
const journal_log = @import("journal_log.zig");
const lora_merge = @import("core").lora_merge;
/// The checkpoints `models` lists, sized, for `tensorfold device`.
Expand All @@ -24,6 +25,7 @@ const usage =
\\ tensorfold plan MODEL [--memory-gb GIB] [--ram GB]...
\\ tensorfold merge MODEL ADAPTER OUT
\\ tensorfold merge DENSE ADAPTER OUT --quantize SHIPPED
\\ tensorfold tfq3 MODEL [--out DIR] [--profile 4b|3.5b|3b] [--target-gib GB] [--fit auto|GB] [--native]
\\ tensorfold log [list|show ID|follow] [PATH] [--json] (the request journal, read-only)
\\
;
Expand All @@ -32,7 +34,7 @@ const usage =
pub fn wants(args: []const []const u8) bool {
if (args.len == 0) return false;
const cmd = args[0];
return std.mem.eql(u8, cmd, "models") or std.mem.eql(u8, cmd, "info") or std.mem.eql(u8, cmd, "pull") or std.mem.eql(u8, cmd, "merge") or std.mem.eql(u8, cmd, "plan") or std.mem.eql(u8, cmd, "rm") or std.mem.eql(u8, cmd, "log");
return std.mem.eql(u8, cmd, "models") or std.mem.eql(u8, cmd, "info") or std.mem.eql(u8, cmd, "pull") or std.mem.eql(u8, cmd, "merge") or std.mem.eql(u8, cmd, "plan") or std.mem.eql(u8, cmd, "rm") or std.mem.eql(u8, cmd, "tfq3") or std.mem.eql(u8, cmd, "log");
}

/// Runs a checkpoint subcommand; `argv` is argv[1..] as in cluster.cli.main.
Expand Down Expand Up @@ -109,6 +111,9 @@ pub fn main(init: std.process.Init, argv: []const [:0]const u8) !u8 {
};
return lora_merge.run(init.gpa, init.io, &out.interface, &err.interface, m.dense, m.adapter, m.dest, m.shipped);
}
if (std.mem.eql(u8, args[0], "tfq3")) {
return tfq3.run(a, init.io, &out.interface, &err.interface, env, args[1..]);
}
const info_start = if (args.len >= 2) info.parseStart(args[2..]) else null;
if (info_start == null) {
try err.interface.writeAll(usage);
Expand All @@ -123,6 +128,7 @@ test "wants only the checkpoint subcommands" {
try std.testing.expect(wants(&.{ "merge", "model", "adapter", "out" }));
try std.testing.expect(wants(&.{ "merge", "dense", "adapter", "out", "--quantize", "shipped" }));
try std.testing.expect(wants(&.{ "rm", "Org/Flash@main", "--yes" }));
try std.testing.expect(wants(&.{ "tfq3", "Qwen/Qwen3.8-27B" }));
try std.testing.expect(wants(&.{"log"}) and wants(&.{ "log", "show", "chatcmpl-a" }));
try std.testing.expect(!wants(&.{"run"}) and !wants(&.{}) and !wants(&.{"serve"}));
}
1 change: 1 addition & 0 deletions zig/src/cli/cuda_main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const usage =
\\ tensorfold info MODEL
\\ tensorfold pull REPO[@REVISION]
\\ tensorfold rm REPO[@REVISION] [--yes] [--dry-run]
\\ tensorfold tfq3 MODEL [--out DIR] [--profile 4b|3.5b|3b] [--dry-run]
\\ tensorfold log [list|show ID|follow] [PATH] [--json] (the request journal, read-only)
\\ tensorfold lanes MODEL PROMPTS.json [--solo] [--max-tokens N] [--no-drafts] [sampling as run] [--report PATH]
\\ (every prompt through the lane core at once, or one at a time with --solo)
Expand Down
19 changes: 18 additions & 1 deletion zig/src/cli/hub.zig
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,26 @@ pub fn revisionOk(text: []const u8) bool {

/// The cached snapshot serving `repo`: refs/main's revision, else the newest snapshot with a config.json.
pub fn cachedSnapshot(a: Allocator, io: std.Io, hub: []const u8, repo: []const u8) !?[]const u8 {
return cachedSnapshotRev(a, io, hub, repo, null);
}

/// The cached snapshot at one explicit revision, or the ordinary main/newest lookup when revision is null.
pub fn cachedSnapshotRev(a: Allocator, io: std.Io, hub: []const u8, repo: []const u8, revision: ?[]const u8) !?[]const u8 {
const dir_name = try repoDirName(a, repo);
const root = try std.fs.path.join(a, &.{ hub, dir_name });
const snapshots = try std.fs.path.join(a, &.{ root, "snapshots" });
if (revision) |requested| {
if (!revisionOk(requested)) return null;
if (readSmall(a, io, try std.fs.path.join(a, &.{ root, "refs", requested }))) |ref| {
const rev = std.mem.trim(u8, ref, " \r\n");
if (hexSha(rev)) {
const snapshot = try std.fs.path.join(a, &.{ snapshots, rev });
if (isDir(io, snapshot)) return snapshot;
}
}
const snapshot = try std.fs.path.join(a, &.{ snapshots, requested });
return if (isDir(io, snapshot)) snapshot else null;
}
if (readSmall(a, io, try std.fs.path.join(a, &.{ root, "refs", "main" }))) |ref| {
const rev = std.mem.trim(u8, ref, " \r\n");
// The ref names the snapshot dir: only a 40-hex git sha is ever joined into a cache path.
Expand All @@ -100,7 +118,6 @@ pub fn cachedSnapshot(a: Allocator, io: std.Io, hub: []const u8, repo: []const u
if (isDir(io, snapshot)) return snapshot;
}
}
const snapshots = try std.fs.path.join(a, &.{ root, "snapshots" });
var dir = std.Io.Dir.cwd().openDir(io, snapshots, .{ .iterate = true }) catch return null;
defer dir.close(io);
var newest: ?[]const u8 = null;
Expand Down
Loading
Loading