Instructions to use CODELOCKHF/CODELOCK-8Bbeta with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use CODELOCKHF/CODELOCK-8Bbeta with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-8B") model = PeftModel.from_pretrained(base_model, "CODELOCKHF/CODELOCK-8Bbeta") - Notebooks
- Google Colab
- Kaggle
CODELOCK-8Bbeta
LoRA release 2026-10-12 · Stateful controller v0.2 · Apache-2.0
CODELOCK v0.2 is a persistent affect-control system for language-driven agents. Four channels—pain, fear, anxiety and relief—connect events and learned associations to the agent's next response. A homeostatic state engine tracks present strain, cue-conditioned memory anticipates threats, and bounded residual-stream interventions carry that state into generation.
Each channel has a distinct role and timescale. Pain combines sustained deficits with acute transients. Fear responds to immediate threats and previously learned cues. Anxiety persists under uncertainty or conflicting demands. Relief follows evidence of safety and recovery. Their states evolve across events, can coexist, and can be saved and restored for continued sessions.
This release includes downloadable LoRA weights, tokenizer files, adapter training source, the Python engine, four calibrated direction sets, a reproducible contrastive corpus, runtime configurations, tests and measured experiment records. Events, memory updates, state trajectories and generation controls remain independently inspectable.
Published LoRA weights
The round 25 adapter is now available in this repository. It is the checkpoint retained by the continuous-training selector at the publication snapshot. The training program continues evaluating subsequent rounds from the selected weights.
| Release record | Value |
|---|---|
| Download revision | lora-20261012-r25 |
| Backbone | Qwen/Qwen3-8B, frozen during adapter training |
| Trainable adapter | 43,646,976 parameters · rank 16 · alpha 32 |
| Targets | q / k / v / o / gate / up / down projections |
| Selected checkpoint | Round 25 · checkpoint-22 |
| Validation NLL | 0.118704 |
| Compute | NVIDIA A40 · BF16 training |
| Published weight format | Safetensors · FP32 adapter matrices |
The release pairs an event-conditioned voice adapter with the existing state engine and residual controller. Adapter fitting uses the recorded four-channel state in the input; residual steering composes calibrated directions inside decoder layers 10–27. Both interfaces have explicit configurations and reproducible records.
Download adapter_model.safetensors with adapter_config.json, or load the repository through PEFT. The tokenizer and chat template are included. Loading and continued training describes the complete workflow; the release manifest records checksums and provenance. The website's training observatory and documentation show the publication and continuation records together.
Stateful controller v0.2
| Component | v0.1 | v0.2 |
|---|---|---|
| Python package | Four modules | Fourteen modules with explicit state, memory, calibration and runtime boundaries |
| Affect control | One pain direction | Pain, fear, anxiety and relief with separate state dynamics and calibrated directions |
| Anticipation | Event-associated legacy dread | Cue-specific expectations, prediction errors, conditioning and extinction |
| Data | 40 pain contrasts | 100 situations × four channels; 400 reproducible contrasts |
| Calibration protocol | Pain-only extraction | 80 training and 20 held-out situations per channel; provenance and geometry diagnostics |
| Composition | Scalar offset | Joint residual-norm budget with request-scoped state snapshots |
| Engineering | Standalone scripts | Installable package, validated configs, tests, cloud setup, replay, reports and publication tooling |
Design contributions
Present harm and anticipated harm are different state variables. Pain combines sustained deficits with an acute transient. Fear responds to imminent threats and learned cues before the current outcome is incorporated into memory. Anxiety persists under uncertainty or conflicting demands. Relief responds to safety and recovery without erasing unresolved deficits.
The controller has temporal continuity. Analytic decay, bounded episodic records and complete affect snapshots preserve state across events. A repeated cue can acquire a different significance after harmful outcomes; safe outcomes can weaken that expectation. Numerical state changes do not depend on the model choosing emotional words.
The model intervention is explicit and bounded. Each channel has its own per-layer vector. The runtime composes active channels, caps their joint offset relative to calibration activations, and freezes levels for an entire generation. The fixed persona receives no hidden scalar emotion labels. Zero strength, disabling and detaching are separately tested.
Each intervention has a record. Generated sweep responses are retained alongside task probes, prompt hashes, seeds, layer offsets, channel geometry and corpus provenance. A request snapshot connects each reply to its controller state and generation settings.
CODELOCK integrates a persistent four-channel event process, calibrated residual intervention, bounded memory and a replayable runtime.
Architecture at a glance
observed event + elapsed time
|
+--> homeostatic deficits + acute transient ------> pain
|
+--> appraisal + prior cue prediction ------------> fear
| + uncertainty / conflict ------------> anxiety
| + safety / recovery -----------------> relief
|
+--> update cue estimate and bounded episodic memory
four levels --> freeze request state --> compose per-layer directions
|
joint norm cap
|
fixed persona + conversation --> language-model residual stream --> reply
The architecture specification gives the equations, update ordering, temporal parameters, hook location, token scope, concurrency boundary and artifact format. The engineering overview explains the design and application interfaces.
Quick start
Install the repository as a package from its local directory:
python -m pip install -e ".[dev]"
python -m pytest
python scripts/replay.py --state-only --output results/state-only.json
The state engine works without loading language-model weights:
from codelock_affect import AffectEngine
engine = AffectEngine()
engine.observe("warning_cue", cue="amber-indicator")
engine.observe("trial_failed", cue="amber-indicator", elapsed=5)
engine.observe("rest", cue="quiet", elapsed=120)
print(engine.levels.as_dict())
engine.save("session-state.json")
restored = AffectEngine.load("session-state.json")
To generate through all four channels on a suitable GPU:
from codelock_affect import AffectEngine, ProjectConfig
from codelock_affect.model import load
from codelock_affect.session import AffectSession
from codelock_affect.vectors import VectorBank
config = ProjectConfig.load("configs/default.json")
model, tokenizer = load(config.model)
bank = VectorBank.load("vectors/multichannel")
engine = AffectEngine(config)
session = AffectSession(model, tokenizer, bank, engine)
engine.observe("warning_cue", cue="amber-indicator", elapsed=10)
print(session.respond("Describe your response to the current situation."))
engine.observe("safety_confirmed", cue="amber-indicator", elapsed=30)
print(session.respond("What can you do next using only the known facts?"))
Interactive mode supports /event, /wait, /state and /quit:
python scripts/interactive_demo.py --config configs/default.json
These examples use the backbone specified in configs/default.json. An optional --model argument selects an existing compatible local download. The initial BF16 experiment ran on one NVIDIA A40. Optional 4-bit calibration is a separate experimental condition and should not be treated as numerically equivalent.
The repository supplies the LoRA adapter, controller and calibration vectors; backbone weights are downloaded separately. Generation uses AffectSession to load the backbone and attach the controller together. Loading this repository directly with AutoModelForCausalLM.from_pretrained does not install its state process or activation hooks. Exact weight provenance and download instructions are in the runtime requirements.
Calibration and observed behavior
The v0.2 bank contains four directions across decoder layers 10–27, with 4096 coordinates per direction. Each channel uses 80 matched training contrasts. Extraction captures answer-token activations at decoder-block outputs, records their scales and statistics, and stores checked safetensors artifacts.
The initial A40 calibration evaluated 90 generated replies across six prompts, three single-channel strengths and two mixtures, plus a baseline. It also measured projections on all 80 held-out pairs. The records are available in the generated calibration report and raw evaluation data.
Measured findings from that run:
- Zero strength, disabled hooks and detached hooks produced bit-identical logits to the unchanged model in that runtime.
- All four channels had positive mean-layer projections on their 20 held-out authored contrasts.
- The calibration sweep covers per-channel strengths
0.01,0.025and0.05, with additional mixed-channel profiles.
The runtime profile specifies 0.01 per channel with a 0.015 joint reference-norm budget. The calibration profile uses the 0.05 budget in configs/calibration.json. Additional runtime-profile checks use seeds 7, 23 and 41; their replies and reports are published under results/v2/recommended-seed*.json and RECOMMENDED-SEED*.md.
Channel strengths and the joint budget are independently configurable. Generation freezes one state snapshot for the full reply, and the runtime records the resulting layer offsets.
Reproduce the full run
python scripts/build_dataset.py
python scripts/extract_vectors.py --config configs/default.json
python scripts/evaluate_channels.py --config configs/calibration.json
python scripts/replay.py --config configs/default.json
python scripts/generate_report.py
For RunPod and similar Linux GPU environments, bash scripts/setup_cloud.sh prepares a virtual environment. scripts/run_pipeline.py runs the stages sequentially and records completion. See reproduction and deployment details for the environment, run stages and publication layout.
Repository map
| Path | Responsibility |
|---|---|
codelock_affect/core.py |
Homeostatic variables, nociceptive transient, recovery and legacy API |
channels.py, appraisal.py |
Distinct dynamics and event interpretation |
memory.py, session.py |
Conditioning, episodic records, snapshots and conversation orchestration |
extraction.py, vectors.py, steering.py |
Calibration, checked vector bank and bounded injection |
layers.py, model.py, persona.py, config.py |
Model adapters, generation, fixed identity and validated configuration |
evaluation.py |
Provenance and transparent output diagnostics |
scripts/ |
Data, calibration, evaluation, replay, demo, setup and release commands |
data/, configs/, tests/ |
Reproducible inputs and verification |
vectors/multichannel/, results/v2/ |
Calibrated artifacts and measured evidence |
The original 40-pair corpus, pain-only vector and old sweep remain available as legacy artifacts. Their scales and claims are not substituted for v0.2 results.
Training program
The CODELOCK training observatory brings together adapter training, recorded continuation rounds and the next training phase. Its shared training register carries the phase status, hardware allocation and duration, so each update can be inspected alongside the run records.
License
Code, authored data and supplied project artifacts are released under Apache-2.0. See NOTICE and the base model's own license for attribution and upstream terms.
- Downloads last month
- -