oa::ml::byte

Module published by the oa::ml module.

MdRust public API

Public Functions

pub fn decode(logits: &Matrix) -> Result<Vec<u8>>
pub fn decode_text(logits: &Matrix) -> Result<String>
pub fn encode(engine: &Engine, bytes: &[u8]) -> Result<Matrix>
pub fn encode_batched(engine: &Engine, bytes: &[u8]) -> Result<Matrix>
pub fn encode_text(engine: &Engine, text: &str) -> Result<Matrix>
pub fn sample( logits: &Matrix, temperature: f32, top_k: i32, top_p: f32, seed: u64, ) -> Result<Vec<u8>>

Public Constants & Variables

pub const BOS: u8 = 0x01;
pub const EOS: u8 = 0x02;
pub const PAD: u8 = 0x00;
pub const SEP: u8 = 0x03;
pub const VOCAB_SIZE: usize = 256;

Function Documentation

pub fn decode( logits: &Matrix ) -> Result<Vec<u8>>
Greedily decode one byte from each FP32 logit row. This is an explicit submission, completion, and compact host-read boundary. Errors Returns an error unless logits are rank-one [256] or rank-two [N, 256] FP32, or execution/readback fails.
pub fn decode_text( logits: &Matrix ) -> Result<String>
Greedily decode logits and require exact UTF-8 output. Errors Returns the errors from decode or crate::ErrorKind::DataLoss when the decoded byte stream is not UTF-8.
pub fn encode( engine: &Engine, bytes: &[u8] ) -> Result<Matrix>
Upload raw bytes as a rank-one U8 Matrix. Errors Returns an error when allocation or upload fails.
pub fn encode_batched( engine: &Engine, bytes: &[u8] ) -> Result<Matrix>
Upload raw bytes as one batched U8 sequence [1, S]. Errors Returns an error when allocation or upload fails.
pub fn encode_text( engine: &Engine, text: &str ) -> Result<Matrix>
Upload UTF-8 text without tokenization or normalization. Errors Returns an error when allocation or upload fails.
pub fn sample( logits: &Matrix, temperature: f32, top_k: i32, top_p: f32, seed: u64 ) -> Result<Vec<u8>>
Sample one byte from each FP32 logit row. Errors Returns an error for an invalid 256-class logit contract, sampling contract, execution, or readback failure.