extern llm fn, and Spiking NetworksPhase 4 (Stage 4 of docs/04-roadmap.md and docs/03-specification.md §14) brings first-class AI and differentiable/probabilistic/symbolic constructs into the self-hosted Lume compiler (lumec) and lcaas without compromising Lume’s core invariants (stage2 == stage3 bit-identical bootstrap, Zero-C steady state, and sound QF_LIA verification).
[T0300]) & std.tensor04_parser_decls.src, lcaas.src):
tensor[T, d1, d2, ...] parses into TyTensor(elem_ty, dims) where dims is a list of dimension symbols ("784", "128", "batch", "n").06_typecheck.src, 06b_phase3.src, lcaas.src):
fn forward(m: Mlp, x: tensor[f32, batch, 4]) -> tensor[f32, batch, 4]).matmul(A, B) / tensor_matmul(A, B)): requires A: tensor[T, m, k] and B: tensor[T, k2, n] with k == k2, producing tensor[T, m, n].tensor_add, tensor_sub, tensor_mul, tensor_add_bias): requires matching shapes [m, n] vs [m, n] or row-broadcast [1, n].[T0300]: tensor shape mismatch ... (fix-it: ...) (exit 3, zero assembly emitted, and structured JSON diagnostic in lcaas / lume agent).compiler/stage1/tensor.src (use tensor){rows: int, cols: int, scale: int, data: [int]} (supporting exact integer and fixed-point f32 milliscale arithmetic):
tensor_zeros, tensor_ones, tensor_vec, tensor_mat, tensor_get, tensor_set, tensor_shape_str.matmul, tensor_transpose, tensor_add, tensor_sub, tensor_mul, tensor_add_bias, tensor_scale, einsum_ij_jk, einsum_trace, einsum_batch_dot.tensor_relu, tensor_sum, tensor_mean, tensor_argmax_row.model Types, Autodiff (grad/vjp/jvp/vmap/jit) & kernel fnmodel Declarations & Autodiff Transformtype Name = model { ... } (04_parser_decls.src, 06b_phase3.src):
OType(Name, "model")) whose tensor fields form a parameter tree.grad, value_and_grad, vjp, jvp, vmap, jit in 06b_phase3.src & lcaas.src):
grad(f) synthesizes a symbolic derivative function __ad_grad_<f> by differentiating functions in the supported polynomial/piecewise fragment (Num, Var, +, -, *, let, if, relu, and sq) with respect to the first parameter. Any non-polynomial operator (/, %, comparisons) or unhandled function call inside a differentiated function is rejected at compile time with [N0400] (exit 3 in lumec, "code":"N0400" in lcaas, #184), never silently returning 0. For 2D tensor models, mlp2_grad in std.nn provides reverse-mode backpropagation. Honest limit: jit(f, ...) currently lowers to a plain call of f (an identity wrapper, no compilation, #10; see n4_lower_ad_call in 06b_phase3.src).jvp(f, x, dx) computes forward-mode directional derivative grad(f)(x) * dx; vjp(f, x, dy) computes reverse-mode pullback dy * grad(f)(x); vmap(f, xs) maps f across a batch list.kernel fn, @schedule, @autotune, #250):
kernel fn declarations are statically checked for accelerator purity (rejecting io, fs, net side effects inside a kernel with [E0200] and non-scalar constructs with [K0400]), lowered from their actual AST bodies (Num/KNum, Var/KVar, Bin/KBin arithmetic & relational comparisons, If/KIf, LetIn/KLet) into SSA CUDA PTX 8.0 (ld.param.s64, mov.s64, add.s64, sub.s64, mul.lo.s64, div.s64, rem.s64, setp.<cmp>.s64, selp.s64, st.global.s64) and Vulkan SPIR-V 1.6 (OpConstant, OpIAdd, OpISub, OpIMul, OpSDiv, OpSMod, OpSGreaterThan/OpSLessThan/OpIEqual, OpSelect, OpStore) via kernel_emit_ptx/kernel_emit_spirv (compiler/stage1/nn.src) and lume agent kernel (cs_ptx_lower_e/cs_spirv_lower_e in compiler/stage1/lcaas.src), and executed on instruction-level PTX 8.0 (ptx_vm_exec / cs_ptx_vm_exec) and SPIR-V 1.6 (spirv_vm_exec / cs_spirv_vm_exec) virtual machine emulators, verifying bit-exact agreement across PTX VM, SPIR-V VM, and Lume-Core evaluation ("gpu_emu_verified": true). Direct hardware GPU driver launch (CUDA Driver API cuLaunchKernel / Vulkan vkCmdDispatch) remains a future runtime extension when a physical GPU is present.compiler/stage1/nn.src (use nn)mlp2_new, mlp2_forward, mlp2_loss, mlp2_grad, mlp2_accuracy), optimisers (sgd_step_mlp2, adam_init_mlp2, adam_step_mlp2), and content-addressed serialisation (model_content_hash, model_save_safetensors, model_load_safetensors, model_export_onnx). Honest limit: model_save_safetensors / model_export_onnx return descriptor strings (JSON-like shape metadata), not valid safetensors/ONNX files (#9).prob Effect, Datalog rule, extern llm fn & std.neuroprob Effect)prob effect (sample_dist, observe_lik) discharged by inference handlers (infer_mcmc, infer_svi, infer_smc) over Beta, Bernoulli, and Normal distributions. Honest limit: inference is a closed-form Beta-Bernoulli posterior mean; infer_svi and infer_smc are aliases of infer_mcmc, and no sampling is performed (#6).rule Declarations (std.rules)rule name(params) = expr (and rule name(params) when cond = expr) compiles to NRuleDecl + callable rule_<name> predicates; the runtime helper is datalog_closure (ai_runtime.src), a naive transitive-closure iteration over edge relations (not semi-naive, and there is no datalog_fixpoint).extern llm fn & Deterministic Replay (std.llm)extern llm fn name(params) -> Ret / {llm} requires ... ensures ... declares an AI-backed function whose signature defines its decoding schema and whose ensures clause validates output before discharging unverified[Ret] provenance ([A0003]).ai_runtime.src: budget enforcement (llm_local_handler, llm_charge, llm_within_budget) and deterministic record/replay evaluation (llm_replay_case, llm_eval_suite). The contract-repair step is a hard-coded invoice example (llm_extract_invoice_repaired), not a general repair loop; llm_call_with_repair and llm_budget_charge do not exist.std.neuro)lif_neuron_new, lif_step, lif_run_Currents; there is no spiking_network_run) operating over deterministic logical time (std.time.logical).docs/04-roadmap.md §Stage 4.9)examples/apps/mnist/: End-to-end MLP digit classifier trained in pure Lume with grad + Adam, verified contracts (lume prove), safetensors + onnx export, and 100% test suite pass.examples/apps/agent/: Autonomous invoice & policy reconciliation agent combining typed tools, table memory, Datalog rule inference, extern llm fn planner with contract-driven repair, supervisor fault tolerance, and deterministic test llm replay evaluation.