All MicroEvals
Read the complete specification before producing output. Bui...
Create MicroEval
Header image for Read the complete specification before producing output. Bui...

Read the complete specification before producing output. Bui...

Prompt

Read the complete specification before producing output. Build from scratch a complete, production-ready, standalone language-model training and inference runtime implementing the focus-point regulator architecture named Cardinal Polarity Focal-Point Execution Graph, abbreviated CPFPEG. Treat CPFPEG as an August 15, 2026 cognitive-topological execution-graph method with no prior public implementation, but do not rely on any external paper or undocumented material; implement the concrete operational definition given here. The complete deliverable consists of exactly one file named `main.zig`. Output the complete, unabridged contents of `main.zig` only. Do not output explanations, Markdown, pseudocode, TODOs, placeholders, mock logic, dummy data, simulated behavior, hard-coded answers, omitted sections, or abbreviated code. The source code must be completely comment-free: no `//`, no `/* */`, and no documentation comments. The program must compile and run in a default Replit Zig environment with `zig run main.zig -- selftest`, using only the Zig standard library. Do not use Python, PyTorch, TensorFlow, Mamba, external machine-learning frameworks, external libraries, existing LLM code, transformer attention, or any conventional neural-network architecture dependency. Implement CPFPEG as a real graph-based runtime whose root execution engine controls tokenization, graph memory, sparse matrix propagation, scheduling, persistence, training, inference, and stabilization. Convert the architecture terms into concrete software behavior as follows: high internal tension means measurable compute-load asymmetry, prediction entropy, memory pressure, and queue imbalance; ideological tension means conflicting predictive evidence inside the model state; structural result means real generated tokens, graph updates, and scheduler decisions; open cardinal polarity means a four-component runtime signal derived from novelty, recurrence, branching entropy, and integrity risk; protective instinct means fault tolerance, memory safety, checksum validation, atomic persistence, overflow prevention, and deterministic recovery from invalid input or corrupted model files. Implement a command-line interface with these modes: `selftest`; `train --input <corpus_path> --output <model_path> [--order N] [--max-vocab N] [--threads N]`; `infer --model <model_path> --prompt <text> [--tokens N] [--temperature F] [--top-k N] [--top-p F] [--seed N] [--threads N]`; `chat --model <model_path> [--temperature F] [--top-k N] [--top-p F] [--seed N]`; and `benchmark --model <model_path> [--prompt <text>] [--tokens N] [--threads N]`. Include strict argument validation, useful runtime error messages, deterministic seeded generation, and nonzero exit behavior for invalid usage or corrupted state. Implement tokenization from scratch. Use a byte-preserving tokenizer with token IDs for all 256 byte values plus learned multi-byte n-gram tokens discovered from the training corpus. Build the learned token graph by counting frequent byte spans without loading the full corpus into memory. Encode with deterministic longest-match content-addressed lookup and decode losslessly back to bytes. Serialize and deserialize the vocabulary in the model file. Implement graph memory from scratch. Store CPFPEG nodes for context states and token states, edges for observed transitions, weighted counts, recency, polarity vectors, tension values, and adjacency ranges. Use content-addressed hashing with collision resolution. Organize nodes and edges into memory blocks with capacity, usage, generation, integrity metadata, and compaction support. Implement allocator-aware initialization and deinitialization for every structure with no intentional leaks. Implement training as a streaming two-pass pipeline when possible: first learn tokenizer spans, then build the transition graph for context orders from 1 through `--order`. Update node counts, edge counts, transition weights, recency, local entropy, tension, and polarity metrics. Do not store the full corpus in memory. Make training deterministic for identical inputs and parameters. Implement inference as CPFPEG graph propagation. Maintain an active focus vector from the current context. Compute internal tension as a normalized weighted combination of prediction entropy, memory pressure, graph branching variance, and worker-queue imbalance. Compute cardinal polarity as novelty, recurrence, branching entropy, and integrity-risk components. Detect open cardinal polarity when the polarity spread and tension exceed adaptive thresholds. Use block-sparse matrix-vector multiplication over graph adjacency to propagate focus and score candidate next tokens. Combine transition probability, context backoff, focus alignment, recency, and polarity alignment into logits. Implement temperature, top-k, top-p, and deterministic seeded sampling. Emit generated bytes directly and support interactive chat mode. Implement matrix operations directly in Zig. Include dense matrix multiplication, sparse matrix-vector multiplication, stable log-sum-exp normalization, entropy calculation, and probability sampling. These kernels must be used by the tokenizer analysis, graph training, inference scoring, or selftests; they must not be unused placeholder functions. Implement a dynamic task scheduler. Detect available CPU threads, allow `--threads`, support single-thread deterministic fallback, partition graph and memory blocks into jobs, and map jobs to worker threads based on internal tension and open cardinal polarity. Use safe Zig synchronization primitives. Ensure reductions are deterministic or explicitly ordered so repeated runs with the same seed and model produce the same output. Implement protective stabilization. Use bounds checks, checked arithmetic where overflow is possible, robust error unions, validated casts, allocation failure handling, and cleanup on all failure paths. Persist models in a binary format with magic bytes, version, endianness marker, hyperparameters, tokenizer data, graph data, block metadata, and SHA-256 integrity hashes using Zig standard crypto. Save atomically through a temporary file and rename. Load only after full structural validation and checksum verification. Implement `selftest` and Zig `test` blocks inside the same file. Tests must verify tokenizer roundtrip, learned token insertion, graph training on deterministic in-memory test vectors, sparse propagation, dense matrix multiplication, serialization/deserialization integrity, checksum rejection of corrupted model data, deterministic sampling, scheduler consistency, and CLI argument parsing. Test content must be used only for verification, not as hidden production model data. Optimize for low latency and low memory usage on CPU hardware. Avoid unnecessary allocations in inner loops, reuse buffers, compact graph blocks after training, and stream file I/O. Do not make unverifiable claims in output; implement measurable behavior. Every code path must be functional and production-ready. Output exactly the complete `main.zig` source file and nothing else.

Response not available

Drag to resize

Response not available

Drag to resize
Drag to resize
Drag to resize