Direct Weight Construction for Transformers: Training-Free Full Scores in Algorithmic Tasks

    This article explains a novel approach called "weight-space programming," where large language models generate executable code that directly constructs Transformer weights instead of relying on backpropagation and gradient descent. It details the closed-loop process of task formalization, evaluation, code generation, and hidden-set validation, and reports that in 13 categories of complex algorithmic tasks across 26 independent runs, constructed networks achieved 100% accuracy on hidden test sets. The article also compares this method with traditional training, outlines engineering best practices, and clarifies its limitations—it is not a universal replacement for pretraining but a complementary, interpretable path for deterministic, rule-based tasks.

    From “Tuning Parameters” to “Directly Constructing Weights”

    The mainstream path in deep learning typically involves designing a network architecture, preparing data, defining a loss function, and then repeatedly updating parameters via backpropagation and gradient descent. This approach is general-purpose, but it comes with clear trade-offs: high training costs, poor interpretability of the learned weights, and a heavily empirical tuning process. For many deterministic algorithmic tasks, what we actually need is not to “infer statistical patterns from data,” but to have the model internally and precisely implement a specific computation—such as comparison, sorting, search, string matching, dynamic programming, or graph traversal.

    “Weight-space programming” offers a different perspective: instead of treating weights as black-box values that only an optimizer can search for, weights are viewed as program states that can be directly constructed by code. A frontier large language model, guided by task specifications, constraints, and evaluation feedback, generates a piece of code that builds weight matrices. That code directly instantiates the parameter matrices of each Transformer layer. The entire process does not rely on backpropagation or massive training samples; it effectively converts the ability to “write algorithms” into the ability to “write weights.”

    In public research descriptions, a team refers to this direction as “interpretable weight-space programming.” In 13 categories of complex algorithmic tasks, across 26 independent runs, the constructed neural networks achieved 100% accuracy on hidden test sets. This result should be understood within its specific task distribution and evaluation conditions: it demonstrates that for well-defined algorithmic tasks with clear input-output mappings, direct weight construction is a viable path—but it does not imply that it can replace all pretraining and fine-tuning.

    Core Mechanism: Letting the Model Generate “Weight Builders”

    It is important to clarify that “hand-writing weights” does not mean having the model manually fill in millions of floating-point numbers. Instead, the model generates executable weight-construction logic. This logic may include loops, conditional branches, matrix initializations, constant tables, routing rules, and inter-layer connection relationships. Executing this logic yields a complete set of Transformer parameters.

    A typical weight-space programming loop consists of the following steps:

    1. Task Formalization: Convert the task description into a formal input-output specification, including input dimensions, output format, boundary conditions, error handling, and test constraints.
    2. Evaluator Construction: Prepare both public test sets and hidden test sets. The evaluator returns only pass rates, failure examples, and discrepancy information—no gradients.
    3. Weight-Builder Code Generation: The large language model generates code that constructs weights based on the specification and prior feedback. The code is responsible for creating the embedding layer, attention layers, feed-forward layers, output heads, etc.
    4. Weight Instantiation and Audit: Execute the construction code to obtain a weight dictionary. Simultaneously check tensor shapes, value ranges, determinism constraints, and interpretable structures.
    5. Hidden-Set Validation: Validate on hidden test sets that were not used during generation. If validation fails, the failure patterns are fed back to the model for another round of correction.
    6. Version Freezing: Once validation passes, the construction code, weight summary, evaluation report, and task specification are versioned together for reproducibility and auditability.

    Illustrative pseudocode:

    1. function compile_weights(task_spec, public_tests, hidden_tests):
    2. rules = formalize(task_spec)
    3. verifier = build_verifier(rules, public_tests, hidden_tests)
    4. feedback = []
    5. for round in range(MAX_ROUNDS):
    6. code = llm_generate_weight_builder(
    7. prompt = WEIGHT_PROGRAM_PROMPT,
    8. spec = rules,
    9. previous_feedback = feedback
    10. )
    11. weights = execute_weight_builder(code, rules)
    12. audit_report = audit_shapes_and_constraints(weights, rules)
    13. if not audit_report.passed:
    14. feedback.append(audit_report)
    15. continue
    16. eval_report = verifier(weights)
    17. if eval_report.hidden_pass_rate == 1.0:
    18. return weights, code, eval_report
    19. feedback.append(eval_report)
    20. raise CompileError("Failed to construct weights that pass hidden tests within the allowed rounds")

    The key insight of this pseudocode is that the optimizer is replaced by a “generate–execute–evaluate–feedback” compilation loop. The model does not update weights via gradients; instead, it modifies the weight-construction code to correct the underlying computational logic.

    Why 100% Is Achievable on Specific Tasks

    First, algorithmic tasks are strongly deterministic. Sorting, searching, string processing, and dynamic programming typically have well-defined input-output specifications, and correctness can be precisely determined by test cases. If the constructed Transformer can stably implement an equivalent computational graph, it becomes possible to achieve full marks on hidden sets.

    Second, weights are directly constructed by code, avoiding numerical errors introduced by random initialization and optimization. Traditional training can suffer from local optima, learning rates, batch sizes, and random seeds; direct construction is more like “compilation”—as long as the logic is correct and numerically stable, the result is more reproducible.

    Third, frontier large language models possess strong code-generation and logic-decomposition capabilities. They can break a task specification into sub-modules and map those sub-modules to attention routing, piecewise functions in feed-forward networks, symbolic encodings in embedding tables, and decision rules in output heads. Transformers have sufficient expressiveness to implement many algorithmic routines through discretization, piecewise linearization, and attention-based selection.

    Fourth, evaluation feedback creates a strong constraint. The model does not generate blindly; it iteratively corrects based on failure examples. The hidden test set verifies whether a truly general logic has been implemented, not just memorization of public examples. The fact that all 26 independent runs achieved 100% indicates good stability of the construction process under the study’s settings.

    However, the boundary must be clearly stated: 100% corresponds only to the specific task set, evaluation protocol, and hidden-test distribution used in the study. It does not mean the model possesses open-domain general intelligence, nor does it imply that all data governance and validation steps can be skipped. For perception, natural language understanding, recommendation, risk control, and other tasks that rely heavily on statistical patterns, traditional training remains indispensable.

    Comparison with Traditional Training Paths

    Dimension Traditional Training Weight-Space Programming
    Weight source Backpropagation & gradient descent LLM generates construction code that directly instantiates weights
    Data requirements Usually large datasets Primarily task specs and evaluation cases
    Interpretability Weights are difficult to interpret Construction logic is readable and auditable
    Iteration mechanism Optimizer updates parameters Evaluation feedback drives code correction
    Suitable tasks Statistical learning, perception, open-domain Deterministic algorithms, small-scale rule modules
    Main risks Overfitting, high training cost, black-box weights Evaluation overfitting, limited task scale, numerical stability issues

    From an engineering perspective, weight-space programming is not meant to replace training but to add a “compilation path” for deterministic logic. It is better suited for small models, algorithmic modules, edge-side rule inference, and scenarios requiring high interpretability. For applications that need large-scale knowledge injection and complex semantic generalization, conventional approaches such as pretraining, fine-tuning, or retrieval augmentation should still be used.

    Engineering Implementation Points

    First, specifications must be verifiable. A task description cannot just be a natural-language goal; it must include input domain, output domain, boundary conditions, handling of abnormal inputs, and test-generation strategies. The more formal the specification, the easier it is to audit the generated code.

    Second, evaluation sets should be layered. Public test sets are used for feedback and correction; hidden test sets for final acceptance; and adversarial test sets for checking edge cases. This prevents the model from generating “special-case logic” that only passes the public examples.

    Third, weight-building code should have a stable interface. For example, it should uniformly return tensor structures for the embedding layer, attention layers, feed-forward layers, and output head—accompanied by shape, type, and value-range declarations. This enables immediate structural audits after execution.

    Fourth, numerical stability checks should be built in. Directly constructed weights may contain extreme values, non-finite values, or distributions that cause attention saturation. The validation phase must check forward-pass determinism, overflow risks, and behavior on abnormal inputs.

    Fifth, versioning and auditing are essential. Every validated construction code, task spec, evaluation report, and weight summary should be frozen. For production systems, record the generation rounds, categories of failed examples, and human review conclusions.

    Sixth, security boundaries must be explicit. Weight-construction code is executable logic and should run in a controlled environment with restricted file-system, network, and system-call permissions. For dynamic generation triggered by external inputs, add sandboxing and manual sampling checks.

    Conclusion

    The idea of having large language models directly “hand-write” Transformer weights essentially replaces “gradient search” with “code construction,” turning the weight space into a programmable space. In deterministic algorithmic tasks, this approach demonstrates strong interpretability and reproducibility: the model continuously refines its construction logic based on evaluation feedback, ultimately writing the algorithm directly into the network’s parameters. The results—13 task categories, 26 independent runs, and 100% accuracy on hidden test sets—indicate that this direction already holds research value within a specific boundary.

    But from an engineering standpoint, caution is warranted: this is not a universal training substitute. It is a compilation-like modeling method for tasks with clearly defined rules. The proper way to use it is as a complement to traditional training pipelines—for algorithmic modules, small-model deployment, interpretable reasoning, and automated weight-generation flows—while controlling risk through rigorous evaluation, structural auditing, and security sandboxing.