pub struct FttsqWriter { /* private fields */ }Expand description
Builds a .fttsq artifact.
Sections are appended in the order given; the writer computes each digest and lays out absolute offsets, so a caller cannot produce an artifact whose directory disagrees with its payload.
Implementations§
Source§impl FttsqWriter
impl FttsqWriter
Sourcepub fn new(
model_family: impl Into<String>,
source_sha256: impl Into<String>,
) -> Self
pub fn new( model_family: impl Into<String>, source_sha256: impl Into<String>, ) -> Self
Starts an artifact for one model family, converted from a checkpoint with source_sha256.
Sourcepub fn license_notice(self, notice: impl Into<String>) -> Self
pub fn license_notice(self, notice: impl Into<String>) -> Self
Sets the Apache-2.0 §4 attribution notice. Required — FttsqWriter::finish refuses without it.
Sourcepub fn model_config(self, config: Value) -> Self
pub fn model_config(self, config: Value) -> Self
Attaches the frozen upstream model config.
Sourcepub fn quantization_manifest(self, manifest: Value) -> Self
pub fn quantization_manifest(self, manifest: Value) -> Self
Attaches the per-tensor quantization policy the license notice refers to.
Sourcepub fn section(
self,
name: impl Into<String>,
access_class: AccessClass,
payload: Vec<u8>,
) -> Self
pub fn section( self, name: impl Into<String>, access_class: AccessClass, payload: Vec<u8>, ) -> Self
Appends a section with its payload. Offset and digest are computed at FttsqWriter::finish.
Sourcepub fn tensor(self, tensor: TensorEntry) -> Self
pub fn tensor(self, tensor: TensorEntry) -> Self
Declares a tensor located inside an already-added section.
Sourcepub fn finish(self) -> Result<Vec<u8>, FttsqError>
pub fn finish(self) -> Result<Vec<u8>, FttsqError>
Serializes the artifact.
The result is re-parsed before being returned, so a writer bug surfaces here rather than as an unreadable multi-gigabyte file discovered hours later.
§Errors
Returns FttsqError::LicenseNoticeMissing without a notice, or whatever the validating
re-parse rejects.
Sourcepub fn write_to_path(self, path: &Path) -> Result<(), FttsqError>
pub fn write_to_path(self, path: &Path) -> Result<(), FttsqError>
Serializes and writes the artifact to path atomically.
Writes to a temporary file beside the destination, fsyncs it, then renames over the target.
A reader therefore observes either the previous artifact or the complete new one, never a
half-written prefix — which matters because a truncated .fttsq is exactly the shape that
digest verification would report as corruption rather than as an interrupted write.
The temporary lives in the destination’s own directory so the rename stays within one
filesystem; rename across mount points is not atomic and would silently degrade to a copy.
On failure the temporary is removed.
§Errors
Returns FttsqError::Io naming the operation and path, or whatever
FttsqWriter::finish rejects.