# Weights as Code: An LLM with 97% Gemini-Generated Initial Weights

> Published 2026-11-30 · https://www.promptzone.com/ishaan_jung/weights-as-code-an-llm-with-97-gemini-generated-initial-weights-fej

A developer has built a functional large language model where **97% of the initial parameter bytes were written as executable code by Gemini 4**. The project, [detailed in a Hacker News thread](https://weights-as-code.pages.dev/) that gained 378 points, inverts the standard training paradigm by using a frontier model to generate the starting weights for a smaller one.

> **Model:** Weights-as-Code | **Parameters:** 58M | **Training Steps:** 500 | **Initial Weights Source:** 97% Gemini 4-generated code | **License:** MIT

## How the Model Was Bootstrapped
Instead of random initialization, the creator prompted Gemini 4 to output Python code that, when executed, would generate tensors constituting a **58-million parameter transformer's weights**. The model architecture is a standard decoder-only transformer. The generated code defined weight matrices with specific numeric values, creating a coherent starting state far from random noise.

This process required multiple refinement cycles. The developer provided Gemini with the model's architecture code and asked it to produce a complete weight-initialization script. After execution, the resulting model was already capable of generating non-random, albeit poor, text before any gradient-based training.


![Weights as Code: An LLM with 97% Gemini-Generated Initial Weights](https://promptzone-community.s3.amazonaws.com/uploads/articles/337swicapze9m5jidjhc.jpeg)

## Benchmarks and Performance
After only **500 training steps** on a filtered dataset, the model achieved a **validation loss of 2.8**. This is a significant result given the unconventional starting point. For comparison, a standard 58M parameter model with random initialization typically requires orders of magnitude more training to reach a similar loss from scratch.

The key metric is the **97% code-generated initial weights**. The remaining 3% were minor corrections or shapes the AI's code missed. Early outputs showed the model could produce basic, coherent sentence structures and follow simple instructions post-training, demonstrating that the AI-generated weights formed a viable, learnable foundation.

| Feature | Weights-as-Code Model | Standard Random Init |
|---------|-----------------------|----------------------|
| Initial State | AI-generated code | Random distribution |
| Training Steps to ~2.8 Loss | 500 | 10,000+ |
| Pretraining Required | No | Yes |
| Primary Innovation | Initialization method | Architecture/scale |

## How to Experiment with the Concept
The complete code, model definition, and the Gemini-generated initialization script are available on GitHub. You can clone the repository and run the training loop on a local machine with a modern GPU.

{% details "Setup and replication steps" %}
1.  **Clone the repo:** `git clone https://github.com/username/weights-as-code` (Use the actual repository link from the source page).
2.  **Install dependencies:** `pip install torch transformers datasets`.
3.  **Review the script:** The key file is `gemini_written_weights.py`, which contains the AI-generated initialization logic.
4.  **Execute training:** Run the main training script to observe the loss curve starting from the unique initial point. The small scale means it can run on a GPU with **8GB VRAM**.
{% enddetails %}

## Pros, Cons, and Immediate Trade-offs
**Advantages:**
*   **Research Novelty:** Provides a completely new method for weight initialization, challenging the standard of random or pre-trained checkpoints.
*   **Rapid Early Convergence:** The model showed meaningful learning extremely quickly, suggesting the AI-generated starting point was in a more favorable region of the loss landscape.
*   **Conceptual Proof:** Successfully demonstrates that a language model can encode another model's knowledge in the form of functional weight-generating code.

**Limitations and Open Questions:**
*   **Scale Unproven:** The experiment was conducted at a tiny 58M parameters. It is unknown if this method is feasible or efficient for billion-parameter models.
*   **Dependence on Frontier Model:** The process requires a highly capable model like Gemini 4, which may be cost-prohibitive for larger weight sets.
*   **No Performance Lead:** The final model does not outperform a classically trained counterpart of the same size; it merely reached competence faster from its unique starting point.

## Alternatives and Related Approaches
This work sits at the intersection of model initialization and knowledge distillation. Direct alternatives include:

*   **Standard Random Initialization (PyTorch default):** The universal baseline, using algorithms like Xavier or Kaiming initialization.
*   **Pre-trained Weight Loading (e.g., from Hugging Face):** The industry standard, where training starts from weights of a model pre-trained on a vast corpus.
*   **Knowledge Distillation:** Training a small "student" model to mimic the outputs of a large "teacher" model, which transfers behavior but not the raw weight structure.

> **Bottom line:** This is a radical experiment in initialization, not a replacement for pre-training or distillation for production models.

## Who Should Explore This Technique
**This approach is valuable for:**
*   **AI Research Scientists** investigating fundamental weight initialization and loss landscape geometry.
*   **Educators** creating demonstrations of how model weights function as encapsulated knowledge.
*   **Experimenters** interested in meta-learning and how AI can generate other AI structures.

**Skip this for now if you need:**
*   **Production-ready models** for deployment.
*   **State-of-the-art performance** on benchmarks.
*   **A practical replacement** for pre-training or fine-tuning established architectures.

The project's greatest utility is in prompting new research questions. Can this method improve fine-tuning efficiency? Could a hierarchy of models iteratively initialize each other? The [Hacker News discussion](https://news.ycombinator.com/item?id=40312345) revealed strong community interest in these theoretical implications, with debates on whether this constitutes "learning" or "compression" by the frontier model.

The final model, while not powerful, stands as a concrete artifact proving that model weights can be a valid output format for generative AI. It shifts a core component of deep learning from a mathematical starting point to a potential generative target.