Architecture Selection and Cost Reduction Practices for Native Multimodal Large Models
This article explores how native multimodal models enable a closed-loop programming workflow through visual feedback and how the Mixture of Experts (MoE) architecture reduces inference costs. It also covers engineering implementation details, cost calculation methods, and selection strategies for alternative AI hardware.
1. Visual Feedback Enabling a Closed-Loop Programming Workflow
When pure text models generate frontend code, they cannot see the rendered page. They can only infer the layout based on code logic, which often leads to spacing errors, element overlaps, and inconsistencies with design drafts that require manual page-by-page inspection.
Native multimodal models jointly learn text and image data during the pre-training phase. They can read design drafts or page snapshots, compare them with requirements item by item, and then provide modification suggestions. This allows “writing code, rendering the page, visual inspection, and correcting code” to form an automated loop.
It is important to note that the meaning of “native” is not uniform across different vendors’ documentation. Some solutions jointly train visual representations during pre-training, while others still rely on independent visual encoders. When selecting a model, the training method described in the official technical documentation should be the primary standard, while marketing terminology should only serve as a reference.
2. How the Mixture of Experts (MoE) Architecture Reduces Inference Costs
The Mixture of Experts (MoE) architecture splits the model into multiple expert sub-networks. During each computation, the router selects only a portion of the experts to participate. As a result, the total number of parameters can be very large, while the number of parameters actually activated per token remains small.
This design brings two direct benefits. First, the larger total parameter capacity allows the model to store more knowledge. Second, the reduced computation per token lowers both inference latency and memory usage.
However, these benefits are not unconditional. Routing itself incurs overhead, imbalanced expert loads can slow down processing, and cross-card communication adds latency. When concurrency is very low or inputs are very short, the cost savings may be limited. Therefore, you should not assume lower costs simply based on “fewer activated parameters”; you must test under your own workloads.
How to Calculate Costs
When calling public cloud APIs, the monthly cost can be estimated as follows:
Monthly Cost ≈ Monthly Input Tokens × Input Price + Monthly Output Tokens × Output Price
When building your own inference service, you can calculate the cost per million tokens:
Cost per Million Tokens ≈ Hardware Hourly Price ÷ Effective Tokens Processed per Hour × 1,000,000
Here, the effective number of tokens processed must be based on actual tested throughput. Actual throughput is often lower than the theoretical peak because incomplete batches, long-tail requests, and memory fragmentation reduce utilization.
Before measuring, it is recommended to record the following metrics: average input length, average output length, time to first token, overall throughput, error rate, and peak concurrency.
3. Engineering Implementation of the Closed-Loop Programming Workflow
The following code is pseudocode used to illustrate the process. The call_llm_api and sandbox_session functions need to be implemented by your project or replaced with specific SDKs.
# Pseudocode: For illustration only. Dependent functions must be implemented based on project requirements.import base64MAX_ITER = 3 # Set a loop limit to prevent the model from repeatedly modifying without convergingdef generate_and_fix_ui(requirement: str) -> str:code = call_llm_api(prompt=requirement, mode="text") # Returns an HTML/CSS/JS stringfor _ in range(MAX_ITER):try:# Sandbox has no external network, restricted CPU and memory, and is destroyed after timeoutwith sandbox_session(timeout_s=20, network=False) as sb:sb.render(code)png = sb.screenshot()except Exception as e:log_error("sandbox failed", e) # Log the error; do not return exception details directly to the userreturn codeimg_b64 = base64.b64encode(png).decode("ascii")review = call_llm_api(prompt=f"The following screenshot should meet the requirement: {requirement}. If there are differences, please list the issues and output the corrected complete code.",images=[img_b64],mode="multimodal",) # Expected to return {"passed": bool, "code": str}if review.get("passed"):return review["code"]code = review.get("code", code) # Keep the previous version of the code if the field is missingreturn code
When implementing this in production, note the following points:
- Code returned by the model is untrusted input. It should undergo static checking before execution and must only be run in an isolated environment.
- Screenshots may contain user data or internal page content. They should be desensitized first and have a defined retention period.
- The JSON output by the model may be incorrectly formatted. Ensure there is a retry or fallback strategy in case parsing fails.
- The number of calls and time consumed in each round must be recorded to facilitate subsequent cost estimation.
4. Selection Strategy for Alternative AI Hardware
Alternative AI chips have entered the large model inference scenario. Some vendors have publicly disclosed cases of using alternative accelerator cards to handle inference traffic, but these cases vary significantly in scale, chip models, and whether hybrid deployments are used. Therefore, a single case cannot be directly used as a selection basis.
When making a selection, you can request standardized data from suppliers, including model version, input/output length, batch size, concurrency, throughput, and time to first token. After obtaining the data, retest using your own business samples and compare with existing solutions.
The table below provides a qualitative comparison. Specific values should be determined based on the formulas and test results mentioned earlier.
| Solution | Cost per Token | Latency | Operational Complexity | Applicable Scenarios |
|---|---|---|---|---|
| Dense LLM | Grows with parameter count | Grows with parameter count | Lower | Scenarios requiring high consistency and simpler deployment |
