Engineering Practices for Text-to-Image Training on Domestic AI Accelerators

    This article outlines a practical engineering approach for training text-to-image systems on domestic AI accelerators. It covers problem definition, a hybrid autoregressive-plus-diffusion architecture, training stabilization, Chinese poster rendering, non-standard aspect ratios, data and evaluation boundaries, deployment considerations, and a recommended implementation order. The focus is on making semantic understanding, pixel generation, text fidelity, and flexible sizing work together as a reproducible system rather than treating a single successful training run as proof of readiness.

    Domestic AI accelerators can now support a complete text-to-image workflow, from data preprocessing to large-scale pretraining. What really determines quality is not whether a training job can run once. It is whether semantic understanding, pixel generation, text fidelity, and flexible sizing can all hold within the same engineering system.

    The sections below are organized around problem definition, architecture division, training implementation, resolution strategy, and acceptance methods. The goal is to avoid treating marketing claims as a technical plan.

    1. The problem is not a single image-quality score

    Commercial image generation commonly fails in three ways: the prompt is misunderstood; the composition is correct but the text is wrong; or the output is cropped into a preset aspect ratio and the layout is ruined.

    Posters, feed covers, long images, and campaign assets often require custom widths and heights. Chinese text must also remain readable, with correct characters, no missing strokes, and no garbled glyphs.

    The system goals should therefore be split into four acceptance criteria:

    • Semantic and global composition: the subject, hierarchy, whitespace, and style match the prompt.
    • Text rendering: glyphs are correct, line spacing is stable, and punctuation is not drawn as decoration.
    • Native aspect ratio: images are generated at the target width and height within an agreed side-length range, rather than generated first and hard-cropped afterward.
    • Reproducible training: data versions, vocabularies, optimizer states, and evaluation sets are traceable.

    If these four items are collapsed into a single “quality score,” it becomes difficult to determine whether a failure comes from data, the decoder, or the resolution strategy.

    2. Why a hybrid architecture is better for “understand first, then write correctly”

    A practical division of labor is to use an autoregressive model in the front stage for semantic planning and global layout, then use a diffusion-style decoder to turn the layout into pixels, with a dedicated glyph encoder constraining text regions. Both sides can be on the order of billions of parameters, but their responsibilities should not overlap.

    The autoregressive part is suitable for three tasks. First, it compresses a long prompt into structured conditions, including the subject, copy, color scheme, and layout intent. Second, it decides the information hierarchy on the canvas before generation, preventing the diffusion process from writing the title incorrectly during the noisy stage. Third, it provides global conditions for later denoising instead of passing only a short text embedding.

    The diffusion decoder is suitable for high-fidelity pixel synthesis, but it is not naturally friendly to sparse, discrete Chinese characters. If the model only relies on cross-attention to “write text along the way,” it may oscillate between high-frequency details and semantics, resulting in visually similar characters, missing strokes, or repeated strokes.

    A more reliable approach is to treat text as an independent condition channel: detect or specify text boxes, encode the character sequence into glyph features aligned with spatial positions, and inject those features into the corresponding regions of the decoder. The front stage handles “understanding”; the text channel handles “writing correctly.” The interface must be explicit rather than left to prompt-engineering luck.

    This “cognitive planning plus pixel decoding” approach is not a proprietary concept of any particular product. It separates language reasoning from image generation and then aligns them. In engineering terms, the system must define how condition tensors are injected at each timestep, the coordinate system for text boxes, and how the text channel is emptied when there are no text samples. Otherwise, mixed training can become unstable.

    3. Stabilizing training on domestic accelerators

    Running the entire pipeline on the same class of accelerator has a clear benefit: data preprocessing, tokenization, forward passes, backward passes, and checkpoint formats remain consistent, reducing numerical differences across devices.

    The framework can be a deep learning framework with good affinity for the target chip. A thin custom training suite can be built on top of it, rather than moving general-purpose scripts over unchanged.

    On the operator side, prioritize fusing high-frequency paths. Optimizer updates, exponential moving averages, normalization, and overlap between communication and computation are common hotspots in large-model training. The purpose of fusion is not to show off techniques, but to reduce memory accesses and synchronization, making throughput more predictable for long sequences and high resolutions.

    Recommended implementation practices:

    • Run small-scale controlled experiments to verify loss curves and gradient norms before enabling fused operators.
    • Validate gradients in text regions separately under mixed precision, so low precision does not erase fine strokes.
    • Save checkpoints for the autoregressive module, the decoder, and the glyph encoder together. Do not save only the half of the weights that “looks like it can generate images.”
    • Keep the data pipeline strictly aligned with training steps. On multi-node setups, sample-order drift can make runs impossible to reproduce.

    Do not treat unpublished fusion implementation details as performance guarantees. Throughput depends on the parallel strategy, sequence length, resolution, and cluster network. Use your own benchmarks as the source of truth.

    4. Chinese poster generation needs separate modeling

    Chinese poster failures differ from natural-scene failures. Font sizes vary widely. Vertical and horizontal text coexist. Artistic text and body copy share the same layout. Background textures can interfere with strokes.

    The data should preserve real poster text boxes, font categories, colors, and layout attributes, rather than storing only a finished image with a short description.

    Training can be staged. First, let the decoder stably write short sentences on simple solid-color backgrounds. Then introduce complex backgrounds, multiple text boxes, and long copy. Only after that should style transfer and lighting effects be mixed in.

    Evaluation should not rely only on an overall aesthetic score. At minimum, report character accuracy, missing-character rate, text-box overflow rate, and line-order error rate. Long text and complex visual text should use a fixed test set. Every time the vocabulary or glyph encoder changes, run a regression.

    Prompt engineering can only mask part of the problem. If the business requires that “the title must be correct character by character,” the inference side should provide optional text-box and copy fields so users can explicitly specify the string to render. Do not expect the model to guess the layout from a colloquial sentence.

    5. Non-standard resolutions: change the token strategy, not post-hoc scaling

    Traditional models often lock output to a few aspect ratios because positional encodings, patch sizes, and training distributions are designed around a fixed grid.

    To support arbitrary ratios, from square images to vertical posters, the token grid must change with the target width and height within an agreed side-length range. Positional encodings must also be extrapolatable or normalized by ratio.

    Practical constraints include:

    • Align side lengths to integer multiples of the patch size or convolution stride.
    • Set an upper limit on total pixels to avoid memory explosions from extremely long vertical images.
    • Cover the target business aspect ratios in the training distribution. Do not pretrain only on square images and then fine-tune on a few ratios.

    At inference time, generate directly at the target pixel size, then apply slight sharpening or compression. This is better than generating a standard image and cropping it, because cropping can cut away the title safe area that has already been laid out.

    An illustrative size plan can be expressed as configuration rather than hard-coded into the model:

    1. min_side, max_side = 1024, 2048
    2. align = 16
    3. width, height = clamp_and_align(request_w, request_h, min_side, max_side, align)
    4. latent_grid = (height // downsample, width // downsample)

    The numbers above only illustrate a common alignment approach. They are not the sole specification of any released model. Before launch, collect real width-and-height distributions from business samples. Handle extreme long images separately, either by queuing them or by reducing resolution.

    6. Data, evaluation, and deployment boundaries

    On the data side, version at least three asset types: image-text pairs, text-box annotations, and size/style labels.

    During cleaning, remove unreadable small text, severe compression artifacts, and watermark interference. Otherwise, the model may treat watermarks as “normal text.”

    Licensing, portrait rights, and trademark compliance must be completed before ingestion. Do not rely on filtering at generation time.

    For evaluation, use three fixed sets: short-prompt composition, complex-scene embedded text, and long-text multi-line layout. Review both automatic scores and human spot checks. Automatic scores are useful for regression. Human review helps catch visually similar characters and layout accidents.

    In comparative experiments, change only one variable at a time, such as swapping the glyph encoder or changing only the aspect-ratio sampling. Otherwise, results cannot be attributed.

    At deployment, return “semantic planning failure” and “pixel or text failure” separately so retries are easier. For the former, rewrite the conditions. For the latter, resample under fixed copy.

    Use object storage for original images and metadata. Use a message queue for asynchronous image generation. Monitor failure rate, text error rate, and latency by aspect ratio, not just average QPS.

    Logs should record the prompt, explicit copy, target width and height, and model version. When a customer complaint appears, the team should be able to reproduce the case offline with the same random seed, then decide whether to add data or change condition injection.

    Do not start with the largest resolution and the longest copy.

    A recommended order is:

    1. Get small-resolution hybrid training working and verify the loss.
    2. Add fused operators and mixed precision, then run numerical comparisons.
    3. Introduce text boxes and glyph conditions, focusing first on short-sentence accuracy.
    4. Expand aspect-ratio sampling and long-text support.
    5. Finally, fine-tune for style and poster templates based on business needs.

    Keep rollback-capable checkpoints at every step.

    If the team only has general diffusion-model experience, it should add interface design for autoregressive conditions and text evaluation, rather than continuing to pile on negative prompts.

    The key risks on domestic accelerators are usually operator numerics, communication overlap, and the data pipeline, not whether the model name sounds good. Writing down acceptance criteria for understanding, correct text, aspect ratio, and reproducibility is closer to a deliverable system than chasing a single demo image.