# version: 0.0.0 # docs/models/rd_flow_64.md — Text-to-image var { model_path = "../models/rd-flow-64/rd-flow-64.safetensors" text_path = "../models/rd-flow-64/text_encoder_model.safetensors" tokenizer_path = "../models/rd-flow-64/text_encoder/tokenizer.json" output_path = "rd_flow_64.png" palette_path = "rd_flow_64_palette.npy" tokens_path = "rd_flow_64_tokens.npy" prompt = "a small red rocket with a round blue window, one tall pine, gradient dusk sky" seed = 1 rng_type = "cpu" width = 64 height = 64 steps = 8 cfg_scale = 4.0 } fn main() { model = load_dit(model_path, family = "rd_flow_64") text = load_text_encoder(text_path, family = "rd_flow_64", tokenizer = tokenizer_path) condition = encode_prompt(text, prompt, width = width, height = height) # The noise sprite is [4, width, height, 1]: ggml fills the fastest axis first, # so a fixed seed hands the model the same noise as the reference's # randn((64, 64, 4)), which is channel-last. noise = tensor::randn_like(tensor::zeros([4, width, height, 1]), rng = make_rng(rng_type, seed = seed)) # rd_flow::sample owns the whole drawing: its shifted schedule, guidance (it # drops the prompt rows, because the model has no negative prompt), the palette # it extracts partway through, and the per-pixel palette token it commits. drawing = rd_flow::sample(noise, predict = predictor(model, condition), steps = steps, guidance = cfg_scale) image::save(output_path, image::to_u8(drawing.image)) # The palette and the pixel map are the lossless form of the sprite: re-decode # them for another size, or save the swatches. tensor::save(palette_path, drawing.palette) tensor::save(tokens_path, drawing.tokens) return {image = drawing.image, palette = drawing.palette, tokens = drawing.tokens} }