Training a Vision Encoder from Scratch: A Technical Architecture Deep Dive

    A detailed breakdown of the technical architecture for jointly pretraining a vision encoder from scratch with a language model, covering the bias-free Transformer design, pixel shuffle downsampling, unified image-video encoding, fixed-ratio mixed data training, and quantization-aware deployment.

    Training a Vision Encoder from Scratch: A Technical Architecture Deep Dive

    1. Background: Why Abandon Pretrained Vision Weights

    When building multimodal large models, the industry has long followed a conventional path: take a vision encoder pretrained with large-scale contrastive learning, freeze or partially unfreeze it, connect it to a language model through an adapter layer, and then run multi-stage alignment training. This approach converges quickly and delivers good early results, but its inherent weaknesses have become increasingly apparent:

    1. Misaligned representation objectives: Pretrained vision encoders are typically optimized for image-text contrastive learning, while the real downstream optimization signal is the autoregressive language modeling loss. These two objectives are not naturally aligned, and visual representations contain a large amount of redundant information that contributes nothing to token prediction.
    2. Stability issues in multi-stage training: When a pretrained vision module is plugged in and unfrozen at a later stage, the abrupt change in gradient distribution can trigger gradient spikes, causing training loss to oscillate or even diverge, requiring extensive extra tuning to suppress.
    3. Architecture constrained by existing weights: Inheriting pretrained weights means inheriting their architectural assumptions (fixed positional encoding schemes, layer counts, normalization strategies), limiting the freedom to co-design the vision and language sides.

    An increasingly popular alternative is therefore to initialize the vision encoder entirely from scratch and pretrain it jointly with the language model on unified corpora in an end-to-end manner. Every update to the visual representations comes directly from the next-token prediction loss, so what the model “sees and how it sees it” is determined by the language modeling objective itself.

    2. Overall Architecture Design

    2.1 Bias-Free Vision Transformer Backbone

    The vision encoder in this approach uses a 27-layer pure Transformer encoder with roughly 400 million parameters. A notable detail is the fully bias-free design across the entire network:

    1. Input image → Patch splitting → Linear embedding (no bias)
    2. → [Multi-head self-attention + FFN] × 27 layers (all bias-free)
    3. → Pixel shuffle downsampling → Projection to the LLM vocabulary dimension

    Removing bias terms from linear layers offers two main benefits. First, bias-free structures behave more predictably under low-precision quantization, since quantization error is not amplified by the additive shifts introduced by biases. Second, bias-free networks combined with the normalization schemes commonly used in modern large models exhibit better scale invariance in practice, which helps numerical stability over extremely long training runs.

    2.2 Pixel Shuffle Downsampling

    The number of vision tokens directly determines how much context a multimodal sequence consumes once it enters the language model. For high-resolution images, splitting with a conventional 14×14 or 16×16 patch size, a 3584×3584 image would produce tens of thousands of tokens—a substantial overhead even in a million-token context window.

    This approach uses 2×2 pixel shuffle downsampling: spatially adjacent 2×2 patch features are concatenated along the channel dimension and then compressed back to the original dimension through a linear transformation, reducing the sequence length to a quarter of the original while preserving local spatial information. In essence, the operation trades channel capacity for sequence length, significantly reducing attention computation and KV cache costs with controllable precision loss.

    2.3 Fully Shared Parameters for Images and Video

    Images and videos share the same set of encoder parameters, with video treated as a sequence of image frames along the temporal dimension. This fully shared design brings three benefits:

    • High parameter efficiency: No separate set of encoder weights needs to be maintained for video, keeping the overall model leaner;
    • Natural transfer: Spatial representations learned from images directly serve video frame understanding, while temporal modeling is handled by the language model backbone at the sequence level;
    • Simplified deployment: Inference only needs to maintain a single set of vision weights, so quantization, caching, and batching strategies can be unified.

    3. Methodology for Joint Pretraining from Scratch

    3.1 A Unified Optimization Objective

    The core of training from scratch is that the vision encoder introduces no independent visual pretraining tasks (such as contrastive loss or masked reconstruction). All of its gradients come from backpropagation of the language modeling loss through the vision token representations. Formally, for an interleaved image-text sequence:

    1. L = - Σ_t log P(x_t | x_<t; Vθ(image))

    where Vθ is the vision encoder initialized from scratch. The update direction of θ is determined entirely by “how to make subsequent text tokens more accurately predicted,” forcing the visual representations to align with the information dimensions that genuinely matter for language tasks.

    3.2 Fixed-Ratio Mixed Data Strategy

    Joint pretraining is performed on roughly 15 trillion mixed image-text tokens, with text and visual data always mixed at a fixed ratio. This may seem simple, but it is actually a key safeguard for training stability: a fixed data ratio keeps the relative scale of vision gradients and text gradients consistent throughout training, avoiding the drastic gradient distribution shifts caused by multi-stage approaches that “train on text first, then suddenly ramp up visual data.” In practice, this method produces a smooth loss curve throughout training with none of the common gradient spikes.

    3.3 Early Fusion

    Vision tokens are fused with text tokens early in the sequence and enter unified attention computation, rather than only interacting across modalities in deeper layers. Early fusion allows every layer of the language model to participate in cross-modal reasoning, which is especially important for tasks requiring deep semantic processing, such as chart understanding, mathematical visual reasoning, and video QA. Evaluation results show that the from-scratch joint pretraining approach not only matches pretrained-initialization baselines, but even achieves better performance on chart, math visual, and video tasks.

    4. Quantization and Inference Engineering

    The vision encoder uses quantization-aware training (QAT) from the start, with weights quantized to 4-bit floating point and activations to 8-bit floating point. The reasons for choosing “training-time awareness” over post-training quantization are:

    1. Vision encoders are sensitive to quantization error in activation distributions; post-training quantization tends to introduce artifacts in high-frequency texture regions;
    2. Quantization-aware training allows the weights to actively adapt to low-precision representations during optimization, keeping inference-time accuracy loss negligible;
    3. Combined with the bias-free architecture, the low-precision numerical path is more regular, making it easier to implement efficiently in inference engines.

    On the engineering side, such vision encoders are typically combined with general-purpose cloud infrastructure—object storage for managing massive image and video corpora, container platforms for elastic inference scaling, and monitoring and alerting for tracking vision token throughput and latency metrics—to build a complete multimodal inference service pipeline.

    5. Synergy Between High Resolution and Long Context

    Supporting input resolutions up to 3584×3584 while integrating seamlessly with million-token context windows relies on three cooperating mechanisms:

    • Downsampling caps token count: 2×2 pixel shuffle compresses per-image token overhead by 4×, preventing high-resolution images from consuming too much of the context budget;
    • Positional encoding extrapolation: The bias-free design combined with rotary positional embeddings gives the encoder better generalization to resolutions not fully seen during training;
    • Dynamic resolution splitting: Actual inputs can adaptively choose splitting granularity based on content, balancing detail preservation and computational cost.

    6. Practical Recommendations and Lessons Learned

    For teams looking to reproduce or adapt this approach, the key takeaways are:

    1. Set the data ratio first: Before scaling up training, determine the fixed text-to-visual data mixing ratio at a smaller scale to avoid mid-to-late-stage adjustments that cause training instability;
    2. Co-design bias-free architecture with QAT: Architectural decisions should account for the target deployment precision format up front, so the architecture and quantization goals don’t work against each other;
    3. Treat the language modeling loss as the only north star: Be cautious about adding auxiliary visual losses, as they may compete with the token prediction objective;
    4. Unify image and video modeling: Use parameter sharing to reduce complexity and let the language backbone learn temporal understanding;
    5. Prioritize charts and structured visual data: A from-scratch encoder has no pretrained “comfort zone” to fall back on, so coverage of charts, documents, and mathematical formulas in the training corpus directly determines the final performance ceiling.

    Conclusion

    The approach of pretraining a vision encoder from scratch jointly with a language model demonstrates that the belief that “visual representations inherently require a separate pretraining stage” is not an unshakable dogma. Through a combination of bias-free architecture, pixel shuffle downsampling, fixed-ratio mixed image-text training, and quantization-aware training, a from-scratch vision encoder can match or even exceed pretrained-initialization approaches in both training stability and final capability, while providing a simpler and more unified engineering foundation for high-resolution, long-context, and video understanding scenarios. This direction deserves serious study and experimentation from multimodal model designers.