Training Image Generation Models End-to-End on Domestic AI Chips: A Technical Breakdown
This article explains how to train an image generation model end-to-end on domestic AI chips, covering the hybrid autoregressive plus diffusion decoder architecture, arbitrary aspect ratio support through tokenizer and positional encoding changes, Chinese poster generation, the training and deployment pipeline built on general cloud capabilities, quality evaluation, and common pitfalls with practical workarounds.
Training Image Generation Models End-to-End on Domestic AI Chips: A Technical Breakdown
1. Why End-to-End Domestic Chip Training Matters
Training image generation models has long depended on a small set of general-purpose accelerators, which creates two practical problems. First, supply is inelastic, so queue times for training jobs are unpredictable. Second, software stack adaptation is expensive: missing operators, mismatched communication libraries, and inconsistent numerical precision show up constantly.
“Running the full pipeline on domestic chips” is more than a slogan. Technically, it means every stage, from data preprocessing and tokenization/encoding through large-scale pretraining to evaluation and inference deployment, runs on the same domestic compute and its accompanying software stack. There is no mixing, such as training on domestic cards but evaluating on general-purpose ones.
The value of a closed loop shows up in three areas:
- Reproducibility: consistent software and hardware versions make experimental conclusions more credible and regression tests more stable.
- Cost control: less cross-platform migration and no duplicate environment maintenance, which cuts engineering overhead.
- Supply security: predictable scheduling and a clear scaling path when compute is tight.
End-to-end does not mean zero adaptation cost. Real projects still have to deal with operator coverage, mixed precision strategy, memory fragmentation, and collective communication efficiency. Practical approaches for these appear below.
2. Hybrid Architecture: Autoregressive for “Reading”, Diffusion Decoder for “Getting It Right”
The current mainstream approach combines a language model’s semantic understanding and global composition ability with a diffusion model’s pixel-level reconstruction ability, forming a hybrid “autoregressive + diffusion decoder” structure. Think of it as a pipeline:
- Semantics and composition stage (autoregressive backbone): a backbone of roughly ten billion parameters unifies text and images into a discrete or continuous token space and predicts token by token, first deciding what to draw, where to place it, and what style to use.
- Pixel reconstruction stage (diffusion decoder): a decoder of a few billion parameters turns the upstream representation back into pixels, handling texture, edges, and text strokes. This is the “getting it right” stage.
The engineering rationale for this split: errors in the semantic stage are structural and the diffusion stage cannot repair them, while diffusion stage errors are mostly local details that iterative denoising can converge on. Decoupling the two makes it easier to tune data mixtures, loss design, and compute allocation separately.
Illustrative training pseudocode (framework agnostic):
# Stage 1: autoregressive backbone pretrainingfor batch in ar_dataloader:tokens = tokenizer.encode(batch.text, batch.image)logits = ar_model(tokens)loss_ar = cross_entropy(logits, tokens.shift_right())# Stage 2: decoder alignment and fine-tuningfor batch in dec_dataloader:cond = ar_model.encode(batch.text) # semantic conditionlatents = vae.encode(batch.image)loss_dec = diffusion_loss(dec_model, latents, cond)loss = loss_ar * 0.0 + loss_dec # freeze backbone, update decoder onlyloss.backward(); optimizer.step()
Practical points:
- Condition alignment: normalize and project the condition representation from the backbone so scale drift does not make the decoder “lose focus”.
- Staged freezing: train the backbone first, then freeze it and train the decoder, then run a small-scale joint fine-tune. This is noticeably more stable.
- Data mixture: the semantic stage leans toward image-text alignment and layout structure data; the decoder stage leans toward high-resolution samples with clear text.
3. Arbitrary Aspect Ratios: Tokenizer and Positional Encoding Are the Key
Traditional models support only a few preset ratios because positional encoding, the token grid, and the training resolution are tightly coupled. Natively supporting arbitrary ratios between 1024x1024 and 2048x2048, including non-standard sizes such as 1240x1600, usually requires three changes:
- Tokenizer strategy: let the encoding grid change dynamically with the target size instead of using a fixed width and height; add tiling and boundary handling for extreme ratios.
- Positional encoding extrapolation: use an interpolable or scalable positional representation so the model stays stable at unseen resolutions.
- Training resolution jitter: sample multiple ratios and sizes randomly during training to build resolution generalization and avoid overfitting to a single ratio.
Memory and throughput also matter. As resolution increases, token count grows roughly quadratically, so gradient accumulation, activation recomputation, and sequence parallelism are needed to cap peak memory.
4. Shipping Chinese Posters Directly
The core difficulty for Chinese is complex glyphs, dense strokes, and strict layout requirements. To improve the rate of directly usable output, work on both the data and decoding sides:
- Data side: build a high-quality Chinese layout corpus covering titles, subtitles, body text, and price tags; annotate font, size, line spacing, and whitespace structurally.
- Decoding side: increase decoding iterations and the guidance strength on text regions; apply local inpainting as a second pass for text-dense areas.
- Post-processing: expose safe area and bleed parameters, and run size validation plus text readability checks before output.
A simplified call shape:
result = generate(prompt="Summer sale poster, prominent main title, blank space at the bottom for a QR code",width=1240, height=1600, # non-standard resolutionsteps=40, guidance=6.5,text_region_boost=True)save(result, "poster_1240x1600.png")
5. Training and Deployment Pipeline: Closing the Engineering Loop with General Cloud Capabilities
Beyond the model itself, pipeline completeness is what really determines iteration speed. Organize it in layers, each mapped to a standard product category available in the industry:
- Data layer: object storage holds image-text pairs and intermediate artifacts, with data versioning for traceability.
- Compute layer: a container platform runs distributed training and inference services, with elastic scaling for peaks.
- Orchestration layer: a message queue decouples data preprocessing from training jobs so long-tail tasks do not slow everything down.
- Observability layer: log service plus monitoring and alerting track loss curves, memory usage, throughput, and failure rates.
- Model serving layer: a unified inference gateway exposes endpoints and supports canary releases and fast rollback.
With the general capabilities of Baidu AI Cloud, these layers map directly onto standard categories such as object storage, container platform, message queue, log service, and monitoring and alerting, with no proprietary interfaces required.
6. Quality Evaluation: Do Not Just Look at “Nice”
Build three layers of evaluation:
- Semantic consistency: image-text match and composition quality, using human ratings combined with automatic metrics.
- Detail fidelity: text accuracy, edge sharpness, and artifact ratio.
- Engineering metrics: time to first token, per-image latency, peak memory, and retry rate.
For non-standard resolutions, build a dedicated test set covering extreme aspect ratios. Otherwise ratio extrapolation can fail in production.
7. Common Pitfalls and How to Avoid Them
- Missing operators: run an operator coverage scan early; replace gaps with equivalent compositions or fall back to a reference implementation.
- Inconsistent precision: fix the mixed precision strategy and random seeds, and establish a regression baseline.
- Memory overflow: try activation recomputation and sequence parallelism first, then reduce batch size.
- Broken text: raise the weight of text samples and keep local inpainting as a fallback.
- Failed ratio extrapolation: introduce resolution jitter during training and cover extreme ratios in the evaluation set.
8. Conclusion
Training image generation models end-to-end on domestic chips is about putting compute supply, software stack adaptation, and hybrid architecture design on the same engineering blueprint. The division of labor between the autoregressive backbone and the diffusion decoder, resolution generalization through the tokenizer and positional encoding, and the pairing of Chinese layout data with local inpainting form a transferable methodology. Combined with general cloud capabilities such as object storage, container platform, message queue, log service, and monitoring and alerting, teams can stand up an integrated loop from data to launch on Baidu AI Cloud and move from “it can generate” to “it is reliably usable”.
