A Practical Guide to Training Multimodal Image Generation Models End to End on Domestic AI Chips

    This article walks through the full engineering pipeline for training a multimodal text-to-image model on domestic (China-made) AI accelerators, organized in the order the work actually happens. It covers heterogeneous data preprocessing with fallback and overlap, distributed training strategies and memory budgeting, numerical stability under mixed precision, non-standard aspect ratios and text rendering, the path from training to serving, and a checklist of common mistakes. Readers will find design principles, simplified loader and training-loop code, and acceptance criteria for validating throughput, peak memory, and convergence in a self-built compute environment.

    1. Background: Why a Fully Localized Training Pipeline Matters

    The capability boundary of multimodal generation models keeps expanding, and text-to-image work has moved from “produces an image” to “produces a usable image.” What industry actually cares about is no longer the visual impact of a single sample, but stability under batch generation, accuracy of text rendering, flexibility in adapting to different resolutions, and compute cost per unit of output. At the same time, diversification of the compute supply chain means more teams must complete the entire chain — data, training, and inference — on non-traditional accelerator hardware.

    Running the whole pipeline on domestic chips is a meaningful milestone because what it validates is not a single operator but the portability of a complete engineering chain: whether data preprocessing can sustain stable throughput in a heterogeneous environment, whether distributed training scales near-linearly on a self-developed interconnect topology, whether mixed precision and memory optimizations still converge when operator coverage is incomplete, and whether the resulting model can actually be delivered in real business scenarios. The rest of this guide breaks that chain down in practical engineering order.

    2. Data: Adapting the Preprocessing Pipeline to Heterogeneous Hardware

    The first bottleneck in multimodal training usually appears on the data side. Image-text pair datasets are large and come from mixed sources, and cleaning plus packing are typically CPU-intensive stages. Without efficient coordination with the accelerator, you get the classic case of compute sitting idle while it waits for data.

    A practical approach is to split the pipeline into three stages:

    1. Decode and clean: normalize formats, regularize sizes, drop corrupted samples, detect text language, and filter by length.
    2. Quality scoring and reordering: filter by an image-text consistency score threshold, then sample in quality tiers so high-quality samples are not diluted.
    3. Pack and index: serialize samples into fixed-length or variable-length shards and build an index that supports random reads for streaming on the training side.

    Two extra points matter in a domestic chip environment. First, the availability of codec libraries and image post-processing operators: if accelerated implementations are missing, keep a CPU fallback path and use multi-process prefetching to overlap I/O with computation. Second, the binding between data shards and training processes: shard alignment plus a prefetch queue works well, so each training process reads only its own shards and cross-node duplicate fetching is reduced.

    Illustrative loading logic looks like this:

    1. class StreamLoader:
    2. def __init__(self, shards, local_rank, world_size, prefetch=4):
    3. self.shards = shards[local_rank::world_size] # Shard alignment avoids duplicate reads
    4. self.queue = []
    5. self.prefetch = prefetch
    6. def __iter__(self):
    7. for shard in self.shards:
    8. for sample in read_shard(shard):
    9. yield preprocess(sample) # Decode, crop, truncate text

    The point is not the code itself but the design principle: treat “fallback-capable” and “overlap-capable” as default constraints for preprocessing in a heterogeneous environment.

    3. Training: Distributed Strategy and Memory Budget

    Three obstacles show up most often in large-scale pretraining on domestic accelerators: graph breaks caused by missing operators, reduced scalability caused by insufficient collective communication efficiency, and limited batch size caused by memory capacity constraints. The general remedies fall into three layers.

    The first layer is compute graph adaptation. The training framework needs to split the model into combinations of operators the backend supports, replacing unsupported operators with equivalent implementations while preserving numerical behavior. In practice, keep an operator coverage list that records fallback implementations and their precision differences, which makes regression validation straightforward.

    The second layer is combining parallelism strategies. The common industry approach mixes data parallelism, tensor parallelism, pipeline parallelism, and sequence parallelism: shard the tensor dimensions first when parameter counts are large, use pipeline splitting with recomputation to reduce activation memory when the model is deep, and split attention computation along the sequence dimension when sequences are long. For ordering, satisfy the memory constraint first, then optimize communication overhead.

    The third layer is numerical stability. Mixed precision training is more prone to overflow and gradient scale drift on heterogeneous backends. Common practices include dynamic loss scaling, keeping higher precision for normalization layers and sum-style reductions, applying global gradient norm clipping, and periodically inspecting the numerical health of weights and activations at key points.

    A simplified training loop skeleton:

    1. for step, batch in enumerate(loader):
    2. with autocast(dtype=bf16):
    3. loss = model(batch) / grad_accum
    4. loss.backward()
    5. clip_grad_norm_(model.parameters(), max_norm=1.0)
    6. optimizer.step()
    7. optimizer.zero_grad()
    8. if step % log_interval == 0:
    9. log_metrics(step, loss, lr, mem_peak) # Observe memory and throughput together

    Any performance conclusion must be based on your own measurements. Interconnect bandwidth, driver versions, and operator library versions differ across clusters and can significantly change actual throughput, so it is worth establishing a fixed benchmark task and adding throughput, peak memory, and convergence curves to routine regression checks.

    4. Capability: Non-Standard Resolutions and Text Rendering

    Real business requirements for an image generation model are often not a fixed size but “output that fits the layout.” The core difficulty in supporting non-standard resolutions is the mismatch between position encoding and the training resolution distribution: once a model converges on square or fixed aspect ratios, extreme aspect ratios tend to break composition and stretch the subject.

    Three general approaches work. First, introduce multi-resolution bucket sampling during training so the model sees a wide enough distribution of aspect ratios. Second, interpolate or scale the position encoding so different resolutions share the same semantic coordinate system. Third, generate in tiles and then fuse them at inference time, preserving global composition while controlling the compute cost of each tile.

    Direct generation of Chinese posters raises a different set of problems: glyph shapes, layout, and semantic alignment. The usual engineering approach decouples text rendering from image generation — the model first produces a background that matches the layout, then text is drawn as vectors in the designated regions, which keeps strokes sharp and font size and weight controllable. If the model must generate text directly, you need high-quality glyph samples on the data side, have to accept a certain character error rate, and should add post-processing validation as a safety net.

    5. Engineering: Closing the Loop from Training to Service

    A finished model is only the starting point. Stable operation in production requires three more capabilities: inference acceleration, including operator fusion, quantization, and cache reuse; elastic scheduling that routes requests of different resolutions to different instances so long-tail requests do not slow everything down; and observability, with dashboards built on logging services and monitoring alerts covering latency, failure rate, and memory usage.

    For cloud deployment, general-purpose components can be combined as needed: object storage for datasets and model artifacts, a container platform for training and inference images, a message queue for smoothing request spikes, and monitoring alerts for anomalies. Teams that want to validate a similar pipeline on Baidu AI Cloud can reuse these general components and engineering constraints directly, with no dependency on any proprietary interface.

    6. Common Mistakes and an Acceptance Checklist

    • Judging by sample images instead of batch consistency: fix an evaluation set and measure composition completeness and text accuracy.
    • Ignoring data throughput: run a pure I/O stress test before training to confirm compute will not sit idle.
    • Skipping numerical inspection: keep precision regression cases for heterogeneous backends.
    • Deferring resolution adaptation to inference: the training distribution sets the ceiling, and post-processing can only compensate.

    In short, completing end-to-end training of a multimodal image generation model on domestic chips is fundamentally a test of systems engineering capability: the data pipeline must be fallback-capable, the parallel strategy must be composable, numerical behavior must be verifiable, and the business capability must be deliverable. Following this path, teams can reliably obtain practical non-standard-resolution generation and direct Chinese poster output in a self-reliant compute environment.