radiance 1.6.0

- Qwen-Image 2.1 and 2.1 Turbo: text to image and image edits over OpenAI's images API,
  /v1/images/generations and /v1/images/edits. An edit takes up to ten pictures and an optional
  mask, outside which the picture comes back exactly as it was; `background: transparent`, png,
  jpeg and webp output, `n` pictures from one prompt, streamed previews (`partial_images`), and
  vLLM-Omni's seed, negative_prompt with true_cfg_scale, num_inference_steps, width and height.
  arch/qwenimage21 serves the diffusers pipeline directory, converted with
  data/recipes/qwen-image-2.1-fp8.recipe (block fp8) or qwen-image-2.1-bf16.recipe.
  deploy/compose/qwen-image-2.1.yaml and qwen-image-2.1-turbo.yaml serve the fp8 containers on
  two cards. Two R9700s make a 2048x2048 picture in 61 s at the base model's 40 steps and in
  13 s with Turbo (56 and 12 s with --tp-wire wht6), a 1024x1024 one in 6.0 and 2.6 s. The
  models are under Qwen's research license, which is non-commercial
- an image generator is a program kind of its own (core/gen): an architecture declares its
  conditioning, denoising and decoding passes, and the driver runs the schedule, the pictures of
  a batch and the conditioning cache. An image model's /v1/models entry is its generator's name
  (qwen-image-2.1, qwen-image-2.1-turbo), and its capabilities and startup banner list only the
  images endpoints
- the tiled prefill GEMMs run their tiles in groups of activation bands, 16 for fp8 and 8 for
  bf16, so an operand larger than the 64 MB cache is read once a group instead of once a band. A
  bf16 GEMM with more than 64 MB of weight runs up to twice as fast
- fixed: a second lane opened in the middle of a step started beside work lane 0 had not
  finished. Gemma 4 26B-A4B opens its lane that way, so its first step after startup could read
  rows not yet written
- startup no longer warns about --checkpoint-slots when it was not passed, nor about an expert
  floor on a model with no experts
- the image's FFmpeg writes png, jpeg and webp (libwebp)
- for out-of-tree plugins: RAD_ABI_VERSION is 16. The op vocabulary gains the image generator's
  ops (conv2d_nhwc, ln_mod, ln_mod_quant_fp8, flow_euler, attn_prefix_self and others; docs/OPS.md,
  "Image generation"), and all_reduce takes an optional `overlap`. Plugins built against 1.5.0
  must be rebuilt
This commit is contained in:
Deadcode committed 2026-10-14 14:03:59 +02:00
1 parent b93b531f63
commit b068190326
66 files changed
+9035 -87

No files matched your search

+1 -1
View File
@@ -19,7 +19,7 @@ extern "C" {
* name, with both versions printed. An OPTIONAL export added beside the existing ones
* (rad_plugin_reference, say) is not a change of shape: a plugin without it is read as answering
* the default. */
#define RAD_ABI_VERSION 15u
#define RAD_ABI_VERSION 16u
/* ================================================================== plugin identity */
/* RAD_PLUGIN_QUANT is a quantiser plugin: rad_quant.h is its whole contract. */
+109
View File
@@ -615,6 +615,106 @@ typedef struct RadEncoderDecl {
int rad_declare_encoder(RadBuilder* b, const RadEncoderDecl* d);
/* ================================================================== the image generator */
/* A PROGRAM THAT MAKES IMAGES: a conditioning network that reads a prompt (and pictures), a
* denoiser that turns a latent from noise into an image's latent over a number of steps, and a
* decoder that turns the latent into pixels. Declared for the reason the logits buffer is: the
* core drives the passes, so it has to be told what it is driving, and only the plugin knows.
*
* DECLARING ONE MAKES THE PROGRAM A GENERATOR, and a generator is driven by passes rather than by
* token steps (RadBatch::gen):
*
* RAD_GEN_PASS_COND one conditioning sequence -- the prompt, and any reference pictures --
* encoded into the generator's KV group. Read once per request (twice
* with guidance: the negative prompt is a sequence of its own).
* RAD_GEN_PASS_DENOISE one step of every image in flight that the pass carries: each image's
* latent rows, read from and written back to the plugin's own state at the
* image's lane, against its conditioning's KV.
* RAD_GEN_PASS_DECODE one image's latent to pixels, in `image_out`, which the core reads back.
*
* A program declares this, logits or pooled vectors -- one of the three.
*
* WHAT IS HERE IS THE MODEL'S CONTRACT WITH A CLIENT: the prompt it was trained on, the sizes it
* makes, the schedule its sampler follows. The core turns a request into passes with it and
* nothing in the core names a model. */
enum { RAD_GEN_PASS_COND = 1, RAD_GEN_PASS_DENOISE = 2, RAD_GEN_PASS_DECODE = 3 };
/* HOW THE GENERATOR'S SEQUENCE IS LAID OUT, which the core builds from the conditioning prompt.
*
* JOINT_GRID the prompt's rows after `drop_prefix`, each media slot standing for `slot_rows`
* rows that a reference picture's latent tokens take in raster order, then the
* image being made. Rotary positions are three components: a text row counts up
* in all three; a picture of h x w tokens holds the count in the first, and its row
* and column, centred on zero (-(n - n/2) .. n/2 - 1), in the other two, after which
* the count moves on by max(h, w). Text rows attend causally, a picture's rows to
* each other both ways, every row to every row before it. */
enum { RAD_GEN_LAYOUT_JOINT_GRID = 1 };
typedef struct RadGeneratorDecl {
const char* name; /* "qwen-image" -- for messages */
int32_t layout; /* RAD_GEN_LAYOUT_* */
/* THE CONDITIONING PROMPT, as text the core tokenises. `{prompt}` is replaced by the user's
* prompt; in `tmpl_edit`, `{images}` by one `tmpl_image` for each reference picture, joined by
* `tmpl_image_sep`. In `tmpl_image`, `{n}` is the picture's 1-based number and `{image}` where
* the picture's own tokens go -- the run the media processor makes of it, its markers
* included. */
const char* tmpl_text;
const char* tmpl_edit;
const char* tmpl_image;
const char* tmpl_image_sep;
/* The tokens this text tokenises to at the start of the prompt are ENCODED but not handed to
* the generator: the conditioning starts after them (a fixed system turn, say). */
const char* drop_prefix;
/* A TRANSPARENT IMAGE, asked for in the words the model was trained on: `{prompt}` is the
* user's description. Empty when the model makes no alpha. */
const char* tmpl_transparent;
/* GEOMETRY. One latent token covers `latent_scale` x `latent_scale` pixels and holds
* `latent_channels` values; a side is a multiple of `size_multiple` pixels; an image has
* `pixel_channels` channels (4: RGBA). A media slot of the conditioning prompt -- one
* encoder output row -- stands for `slot_rows` rows of the generator's sequence. */
int64_t latent_channels;
int64_t latent_scale;
int64_t size_multiple;
int64_t pixel_channels;
int64_t slot_rows;
/* The largest image, in latent tokens: every buffer the plugin sized for one image. */
int64_t max_tokens;
/* Reference pictures: at most `max_refs` a request, each resized to `ref_area` pixels. */
int64_t max_refs;
int64_t ref_area;
/* The size a request that names none is made at. */
int64_t default_width, default_height;
/* THE SAMPLER: flow matching, an Euler step from sigma 1 towards 0.
* A FIXED SCHEDULE: `n_sigmas` values, the terminal 0 implied; a request may not change the
* step count. Otherwise `default_steps` sigmas from 1 to 1/steps, shifted:
* dyn_shift 0 sigma' = shift * s / (1 + (shift - 1) * s)
* dyn_shift 1 mu linear in the image's token count, 256 -> base_shift .. max_seq ->
* max_shift; shift_exp 1: exp(mu) / (exp(mu) + (1/s - 1)), 0: mu / (mu + ...)
* then, with shift_terminal > 0, stretched so the last sigma is shift_terminal. */
int64_t default_steps;
int32_t n_sigmas;
const double* sigmas;
double shift;
int32_t dyn_shift;
int32_t shift_exp;
double base_shift, max_shift;
int64_t base_seq, max_seq;
double shift_terminal;
/* Guidance a request gets when it names none; 1 is off. */
double default_cfg;
/* WHERE THINGS ARE. `max_lanes` images may be in flight at once, each in a lane of the
* plugin's own state; `image_out` is [max_tokens * latent_scale^2, pixel_channels] u8 on the
* device, row-major pixels of the image a decode pass made. */
int64_t max_lanes;
rad_buf image_out;
} RadGeneratorDecl;
int rad_declare_generator(RadBuilder* b, const RadGeneratorDecl* d);
/* ================================================================== diagnostics */
/* A plugin may annotate the graph dump. Free-form, printed under --debug-graph. */
void rad_note(RadBuilder* b, const char* fmt, ...);
@@ -687,6 +787,15 @@ typedef struct RadArchProbe {
* number of its merge), when it declares one: the engine sizes the audio pass with it
* (RadBuildCtx::max_audio_frames). 0 is no audio. */
int64_t audio_frames;
/* AN IMAGE GENERATOR (rad_declare_generator), and the rows its largest pass carries: the
* engine sizes the step for it before declare -- a denoise pass carries an image's every
* latent row at once, twice with guidance -- and turns off what a generator has no use for.
* 0 is a program that generates text or embeds. */
int64_t gen_rows;
/* ...and the patches its conditioning pass encodes at most: every reference picture a request
* may carry, at the size the model resizes them to. The encoder's pass size (max_enc_patches). */
int64_t gen_patches;
} RadArchProbe;
int rad_arch_probe(const RadModelMeta* meta, RadArchProbe* out);
+49
View File
@@ -0,0 +1,49 @@
#ifndef RAD_PHILOX_H
#define RAD_PHILOX_H
/* Counter-based Gaussian noise, the one definition every kernel library computes it by, so an
* image's starting latent is a function of its seed and of nothing else: not the batch it shares a
* pass with, not the rank count, not the order its rows are visited in.
*
* Element e of a seed's stream is Philox4x32-10 at counter (e / 4, 0) keyed by the 64-bit seed,
* its four words made uniform in (0, 1) as ((w >> 8) + 0.5) * 2^-24 and paired by Box-Muller --
* words 0 and 1 give elements 4g and 4g+1 (r cos t, r sin t), words 2 and 3 give 4g+2 and 4g+3.
* f32 throughout. A library's libm may differ from another's in the last place of log, cos and
* sin, so two libraries agree to a tolerance and each agrees with itself exactly. */
#include <stdint.h>
#include <math.h>
#if defined(__HIPCC__)
#define RAD_PHILOX_HD __host__ __device__ __forceinline__
#else
#define RAD_PHILOX_HD static inline
#endif
RAD_PHILOX_HD void rad_philox4x32_10(uint32_t c[4], uint32_t k0, uint32_t k1) {
const uint32_t M0 = 0xD2511F53u, M1 = 0xCD9E8D57u, W0 = 0x9E3779B9u, W1 = 0xBB67AE85u;
for (int r = 0; r < 10; ++r) {
const uint64_t p0 = (uint64_t)M0 * c[0], p1 = (uint64_t)M1 * c[2];
const uint32_t hi0 = (uint32_t)(p0 >> 32), lo0 = (uint32_t)p0;
const uint32_t hi1 = (uint32_t)(p1 >> 32), lo1 = (uint32_t)p1;
const uint32_t n0 = hi1 ^ c[1] ^ k0, n2 = hi0 ^ c[3] ^ k1;
c[0] = n0; c[1] = lo1; c[2] = n2; c[3] = lo0;
k0 += W0;
k1 += W1;
}
}
/* Element `e` of the standard-normal stream of `seed`. */
RAD_PHILOX_HD float rad_philox_normal(uint64_t seed, uint64_t e) {
const uint64_t g = e >> 2;
uint32_t c[4] = { (uint32_t)g, (uint32_t)(g >> 32), 0u, 0u };
rad_philox4x32_10(c, (uint32_t)seed, (uint32_t)(seed >> 32));
const int j = (int)(e & 3u);
const uint32_t wa = c[(j >> 1) * 2], wb = c[(j >> 1) * 2 + 1];
const float ua = ((float)(wa >> 8) + 0.5f) * (1.0f / 16777216.0f);
const float ub = ((float)(wb >> 8) + 0.5f) * (1.0f / 16777216.0f);
const float r = sqrtf(-2.0f * logf(ua));
const float t = 6.28318530717958647692f * ub;
return (j & 1) ? r * sinf(t) : r * cosf(t);
}
#endif /* RAD_PHILOX_H */
+87
View File
@@ -229,8 +229,95 @@ typedef struct RadBatch {
int64_t enc_n_seg;
const int32_t* enc_cu; /* [enc_n_seg + 1] device: segment boundaries in patches */
int32_t enc_max_seg; /* host: the longest segment, which bands the attention */
/* ================================================ image generation */
/* A GENERATOR PASS (rad_declare_generator): RAD_GEN_PASS_*, and `gen_b` what it carries. 0 on
* every step of a program that declared no generator. */
int32_t gen;
const struct RadGenBatch* gen_b;
} RadBatch;
/* WHAT A GENERATOR PASS CARRIES beside the step batch's own fields, which keep their meanings:
*
* COND ONE sequence. `token_ids`, `positions` and `rope_pos` are its conditioning prompt, the
* encoder's input (`enc_*`) is the prompt's reference pictures and `mm_rows` the prompt
* rows the encoder's output rows replace, as on any media step. What is here lays out
* the generator's sequence over those rows and writes it into the KV group.
* DENOISE one entry per (image, conditioning): `cu_seqlens` bounds each entry's latent rows,
* and the KV group's `block_table` and `seqused` name its conditioning's sequence.
* DECODE one image.
*
* Every pointer is device memory unless the name ends in _h. */
typedef struct RadGenBatch {
/* ---- COND */
int64_t rows; /* the generator's rows for this sequence */
/* Where each row comes from: >= 0 the prompt row of that index (the conditioning network's
* output there), < 0 the reference latent row -(1 + src). [rows] */
const int32_t* src;
/* Rotary positions, three components a row. On a COND pass they are laid out SEGMENT BY
* SEGMENT: segment s's [3, length] component-major block starts at element 3 * seg_h[s], so a
* segment's positions are one dense operand. On a DENOISE pass, [3, n_tok] component-major,
* the latent rows'. */
const int32_t* rope;
/* The sequence in SEGMENTS: rows [seg_h[s], seg_h[s+1]), each a picture (`seg_bidi_h` 1, its
* rows attend to each other both ways) or a run of text (0, causal). A segment is never split
* and attends to every segment before it. `seg` is the same offsets on the device; `seg_cu`
* is [n_seg, 2], segment s's own cu_seqlens {0, length}, and `seg_start` [n_seg] its first
* row -- the keys before it, which is its `seqused` when it is run on its own. */
int64_t n_seg;
const int32_t* seg;
const int32_t* seg_h;
const int32_t* seg_bidi_h;
const int32_t* seg_cu;
const int32_t* seg_start;
/* [rows] the KV slot each row is stored at. */
const int32_t* slot_mapping;
/* PIXELS the decoder's encoder takes: `n_px` blocks of `px` [*, pixel_channels] bf16 in
* [-1, 1], block b at pixel px_h[3b], px_h[3b+1] high and px_h[3b+2] wide. The reference
* pictures, in prompt order, and -- with `inpaint` -- a last block that is no reference but
* the picture being repainted, at the size being made: its latents go to the lanes below. */
int64_t n_px;
const void* px;
const int32_t* px_h;
/* [n_px, 2] each block's own cu_seqlens over its latent tokens: {0, (h / scale) (w / scale)}. */
const int32_t* px_cu;
int32_t inpaint;
/* [image tokens] f32: 1 where the image is repainted, 0 where the picture is kept. */
const float* inp_mask;
/* The lanes this conditioning's images run in, which take the repainted picture's latents. */
int64_t n_lane;
const int32_t* lane_h;
/* ---- DENOISE, one value per entry ([n_seq]); on a COND pass `sigma` is one 0, the time
* the conditioning is modulated at */
const float* sigma; /* where the entry's latent is */
const float* sigma_next; /* where this step takes it */
const float* cfg; /* guidance: v = neg + cfg * (pos - neg); 1 without a pair */
/* The entry holding this image's NEGATIVE conditioning, or -1 for none; -2 marks an entry
* that IS one, whose rows serve another entry's step and whose lane it does not move. */
const int32_t* pair;
const int32_t* lane; /* the plugin's lane the image's latent lives in */
const int32_t* lane_dh; /* ... the same, host */
/* RAD_GEN_F_*. */
const int32_t* flags;
/* [n_seq, 2] the image's noise seed, low word first. */
const uint32_t* seed;
/* ---- DECODE */
int32_t dec_lane;
int32_t dec_height, dec_width; /* pixels */
int32_t dec_preview; /* the lane's preview latent, not its state */
} RadGenBatch;
/* An entry's flags on a DENOISE pass. */
enum {
RAD_GEN_F_FIRST = 1, /* the image's first step: its latent is the noise its seed draws */
RAD_GEN_F_INPAINT = 2, /* repaint: after the step, the kept region goes back to the picture,
* noised to sigma_next with the image's own noise */
RAD_GEN_F_PREVIEW = 4 /* write the step's estimate of the clean latent to the lane's preview */
};
/* ================================================================== operands */
/* RAD_OPK_KV names a KV group's pool rather than a buffer: attention and kv_store take the cache
* as an operand, and RadKVGroupBatch carries the slot mapping and the block table but not the