Archived
- 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
73 lines
3.2 KiB
C++
73 lines
3.2 KiB
C++
/* engine_gen.cpp -- the image generator's loop: the driver's passes (core/gen/driver.h) run on the
|
|
* ranks the way the step loop runs token steps, one at a time and each drained before the next.
|
|
*
|
|
* WHY EACH PASS IS DRAINED. A generator pass is tens to thousands of milliseconds of device work,
|
|
* and what decides the next one -- which image finished, which preview a step marked -- is the
|
|
* driver's bookkeeping of the pass just run, not anything the card computes. Waiting for the card
|
|
* between passes costs the few microseconds the host takes to build the next one; issuing ahead
|
|
* would need a second staging region and a commit protocol, for nothing a client could measure.
|
|
*/
|
|
#include "engine_priv.h"
|
|
#include "gen/driver.h"
|
|
|
|
#include <chrono>
|
|
#include <thread>
|
|
|
|
namespace rad {
|
|
|
|
int Engine::gen_loop() {
|
|
if (rad_dev_set(ranks_[0]->device) < 0)
|
|
RAD_ERR("image generator loop: could not bind rank 0's device");
|
|
int step = 0, idle = 0;
|
|
const rad_buf img = ranks_[0]->program.generator.image_out;
|
|
while (!stopping_.load(std::memory_order_acquire)) {
|
|
const RadBatch* b = gen_->next(step);
|
|
if (!b) {
|
|
step_batch_.store(nullptr, std::memory_order_release);
|
|
if (idle < 200) ++idle;
|
|
std::this_thread::sleep_for(std::chrono::microseconds(idle * 50));
|
|
continue;
|
|
}
|
|
idle = 0;
|
|
if (const int ps = prepare_release(b); ps < 0) {
|
|
gen_->shutdown("the engine stopped on an error and is not serving", ps);
|
|
return fail_loop(ps);
|
|
}
|
|
issue_what_.store(kIssueModel, std::memory_order_release);
|
|
step_batch_.store(b, std::memory_order_release);
|
|
barrier_->arrive_and_wait(); /* release the ranks */
|
|
barrier_->arrive_and_wait(); /* wait for them */
|
|
int st = step_status_.load(std::memory_order_acquire);
|
|
if (st < 0) {
|
|
RAD_ERR("generator pass %d failed: %s -- the engine cannot continue", step,
|
|
rad_strerror(st));
|
|
gen_->shutdown("the engine stopped on an error and is not serving", st);
|
|
return fail_loop(st);
|
|
}
|
|
/* A DECODE PASS'S IMAGE, behind it on rank 0's stream: every rank decodes the same pixels. */
|
|
if (const int64_t n = gen_->decode_bytes(); n > 0) {
|
|
const void* src = ranks_[0]->ctx.buf_ptr(img);
|
|
if (!src) {
|
|
RAD_ERR("the generator's image buffer was declared but never planned");
|
|
gen_->shutdown("the engine stopped on an error and is not serving", RAD_E_STATE);
|
|
return fail_loop(RAD_E_STATE);
|
|
}
|
|
st = rad_memcpy_async(gen_->host_image(), src, n, ranks_[0]->ctx.stream());
|
|
}
|
|
for (auto& rk : ranks_)
|
|
if (st >= 0) st = rad_stream_sync(rk->ctx.stream());
|
|
if (st < 0) {
|
|
RAD_ERR("generator pass %d: the device failed: %s", step, rad_strerror(st));
|
|
gen_->shutdown("the engine stopped on an error and is not serving", st);
|
|
return fail_loop(st);
|
|
}
|
|
if ((int)log_level() >= (int)Log::Trace)
|
|
dump_buffers(ranks_[0]->ctx, step, std::getenv("RADIANCE_DUMP_BUF"));
|
|
gen_->done();
|
|
++step;
|
|
}
|
|
return RAD_OK;
|
|
}
|
|
|
|
} /* namespace rad */
|