Multimodal Image Generation on a Fully Domestic AI Stack: End-to-End Training, Text Rendering, and Cost Control
This article walks through the practice of training a multimodal image generation model end to end on domestically produced accelerators and frameworks, covering data preparation, pretraining, instruction tuning, and alignment. It explains why closing the loop across the compute, framework, and model layers shortens debugging paths and makes cost predictable, why text rendering is the real dividing line for image generation, and how a dual-engine architecture (an autoregressive planner plus a diffusion decoder, with a dedicated text enhancement module and OCR read-back verification) addresses it. It also lists the main adaptation points on a domestic software and hardware stack, a layered evaluation framework, inference cost optimizations, and a staged rollout plan with known risks.
1. From “It Trains” to “It Works”: The Real Bar for a Fully Local Stack
Completing the full pipeline on domestic chips and domestic frameworks—data preparation, pretraining, instruction tuning, and alignment—matters for more than substitution. It validates a closed loop in which the compute layer, the framework layer, and the model layer can feed back into one another and be tuned together inside a single stack. The common alternative is to run inference on domestic cards and training on overseas ones. Once training cannot be closed locally, missing operators, numerical anomalies, and communication bottlenecks can only be resolved by waiting on upstream schedules, which puts the iteration cadence entirely out of your hands.
A closed loop delivers three direct benefits. First, the debugging path gets shorter: when loss spikes or gradients misbehave, you can bisect quickly across operator implementations, mixed-precision policies, and parallelism layouts instead of waiting for external support. Second, hardware characteristics can be exploited in reverse: domestic accelerators make their own tradeoffs in high-bandwidth memory capacity and throughput for specific data types, so training scripts can adjust batch size and sequence length ratios accordingly, turning a hardware weakness into an acceptable engineering compromise. Third, the cost structure becomes controllable: compute budgets and supply stability for long training runs are predictable, which matters a great deal for multimodal pretraining that routinely consumes thousands of GPU-hours or more.
One caveat: “fully domestic” is an engineering property, not a quality guarantee. Whether a model is usable still comes down to capability benchmarks and scenario validation.
2. The Core Difficulty: Why Text Rendering Is the Dividing Line
In real business use, image generation is rarely a pure-visual request. A poster must state the event theme and time, a slide cover needs an accurate title, a social banner needs one complete tagline. These scenarios share a trait: one wrong character and the whole image is scrap.
The root cause of the difficulty is a mismatch of representations. Diffusion decoders denoise in a continuous latent space and are naturally good at texture, lighting, and color, but characters are discrete symbols that are extremely sensitive to high-frequency details such as stroke count, relative position of components, and character spacing. A single Chinese character can have a dozen or more strokes; a tiny perturbation in latent space is visually almost invisible, yet after decoding back to pixels it may turn into a different character or a garbled one. Three further difficulties compound this:
- Long text and multi-line layout: as the character count grows, layout consistency, line spacing, and alignment all enter an error-accumulation zone at the same time.
- Glyph diversity: one model must switch among Latin letters, digits, punctuation, and CJK ideographs, whose stroke densities differ enormously.
- Coupling of semantics and visuals: text is both content and a design element, so size, weight, and color must harmonize with the overall composition—it has to be correct and good-looking.
A usable solution therefore has to separate “understand the semantics and plan the layout” from “render pixels and get the characters right.” That is the starting point of the dual-engine architecture.
3. Architecture: A Planning Brain, a Rendering Brush, and a Text Enhancement Module
3.1 The Autoregressive Model Handles Understanding and Planning
An autoregressive multimodal model on the order of ten billion parameters acts as the brain. Its job is to translate a natural-language instruction into a structured drawing plan: what the subject is, which composition and viewpoint to use, the text content fixed character by character, which region each text block occupies, and which font hierarchy and color tendencies to apply. Because autoregressive models are strong at modeling symbol sequences, they are more reliable than a pure diffusion route at generating the correct string character by character—get the text right first, then hand it downstream for rendering.
In engineering terms, the intermediate representation this layer emits is the most important contract in the whole pipeline. Define it as an explicit structure rather than free text so it can be validated and retried:
plan = {"canvas": {"width": 1024, "height": 1024},"subject": "Summer beverage promotion key visual","text_blocks": [{"content": "Cool Summer", "bbox": [80, 60, 640, 220],"style": {"weight": "bold", "color": "#FFFFFF"}},{"content": "Second cup half price · Aug 1 - Aug 31", "bbox": [80, 760, 900, 840],"style": {"weight": "regular", "color": "#FFE9A8"}}],"palette": ["#0E7C86", "#F5F0E1"]}
3.2 The Diffusion Decoder Handles Detail Rendering
A diffusion decoder on the order of seven billion parameters acts as the brush. Conditioned on the plan—text content, region masks, global style—it performs denoising and is responsible for materials, lighting, color, and stroke detail. Injecting text regions as constrained areas markedly reduces the chance of characters being swallowed by background texture.
3.3 The Dedicated Text Processing Module
Between the two engines sits a set of text-specific enhancements: character-level condition injection, glyph reference features, text-region mask protection, and read-back OCR verification after rendering. The last step matters most—read the text back from the generated image with a recognition model, compare it against the planned string, and on mismatch trigger a local repaint rather than a full-image regeneration. This raises the usable rate by a noticeable step at almost no cost to end-to-end latency.
# Pseudocode: generation flow with verification and local repaintplan = planner(instruction)image = diffusion_decode(plan, seed=seed)for attempt in range(MAX_RETRY):recognized = ocr(image, region=plan.text_blocks[0].bbox)if normalize(recognized) == normalize(plan.text_blocks[0].content):breakimage = inpaint_text_region(image, plan.text_blocks[0], seed=seed + attempt)return image
4. Training Adaptation on a Domestic Software and Hardware Stack
Getting multimodal training to run on domestic chips and frameworks usually takes most of the effort in these areas:
- Operator coverage and custom operators: if high-frequency operators are missing—attention variants, variable-length sequence packing, image patch convolutions—fill the gaps with custom operators and run numerical alignment checks (maximum absolute error against a reference implementation).
- Mixed-precision strategy: the vision tower and the text tower differ in sensitivity to numerical range, so use a layered precision policy that keeps normalization layers and loss-related computation in higher precision to avoid silent failures caused by overflow.
- Parallelism layout: data parallelism for the vision encoder, sequence or tensor parallelism for the diffusion backbone, pipeline parallelism for the autoregressive part, with gradient checkpointing to cap peak memory.
- Communication and topology: inter-node bandwidth is the main bottleneck for long-sequence training, so keep split dimensions inside the intra-node high-speed interconnect domain where possible.
- Fault tolerance and checkpoint resume: for long-running jobs, periodic snapshots, faulty-node isolation, and automatic rescheduling are requirements, not options.
- Data pipeline: image-text pair cleaning, text annotation quality, resolution bucketing, and deduplication directly determine the ceiling on text rendering, and investment here typically pays off more than tuning hyperparameters.
5. Evaluation: Don’t Just Watch Leaderboards—Build Your Own Test Set
Public text-rendering leaderboards are a useful reference, but selection for a business requires an in-house evaluation set, layered by dimension:
- Character accuracy: measured with character-level edit distance, reporting both exact-match rate and mean edit distance.
- Layout consistency: how well text regions fit the planned boxes, line alignment, overflow or clipping.
- Semantic consistency: whether the subject matches the instruction; use image-text similarity for a coarse filter, then human review.
- Aesthetics and usability: weight hierarchy, whitespace, color harmony—these need human scoring.
- Stability: reproducibility with a fixed seed, and variance in pass rate across repeated generations of the same prompt.
The test set should cover short titles, long sentences, multi-line text, mixed Chinese and English, digits and dates, rare characters, very small font sizes, and hard samples where text sits on a complex background. Fix the random seed and resolution during evaluation, log the failure type for each case, and build a regression-ready defect list.
6. Inference Cost and Engineering Optimization
Cost is not just unit price; it is cost per usable image. If the pass rate is low, retries multiply the real cost several times over. Levers that combine well include:
- Tiered generation: render a low-resolution draft to confirm composition and text, then refine at high resolution.
- Local repaint instead of full regeneration, with caching of intermediate latents.
- Dynamic batching and continuous batch scheduling to raise throughput.
- Weight quantization and operator fusion to cut single-request latency.
- Prompt templating: fix reusable layout constraints as templates to reduce uncertainty in the planning stage.
For a cloud-hosted service deployment, general-purpose cloud product categories are sufficient: object storage for assets and outputs, a container platform for elastic inference, a message queue for asynchronous task smoothing, and logging plus monitoring with alerts to track failure rate and latency percentiles. General-purpose cloud offerings such as those from Baidu AI Cloud can serve as the foundation for this kind of architecture.
7. Rollout Advice and Risks
For image-text-heavy scenarios such as posters, courseware covers, and social assets, the recommended sequence is: first fix 20–50 real business prompts as a baseline, then compare pass rate and latency between a pure diffusion approach and the dual-engine approach, and only then decide whether to add read-back verification and local repaint. Risks to assess up front: rare characters and very long text remain weak spots, small font sizes on complex backgrounds fail easily, and content compliance review must be built into the pipeline rather than patched on afterward.
Overall, a fully local stack has turned the question from “can we train it” into “how do we train it better.” For developers, real competitiveness comes from the product of data quality, a closed evaluation loop, and engineering optimization—not from a lead on a single model metric.
