Enterprise-100 Qwen3-8B Steering Vectors
Reusable activation-steering artifacts from the
Enterprise-100 database experiment.
They steer Qwen/Qwen3-8B between direct SQL and Python sqlite3/pandas
solutions without changing model weights.
This is an activation artifact repository, not a fine-tuned checkpoint. Load the base Qwen3-8B model separately and apply a vector through a forward hook.
Core result
The principal direction is:
python_minus_sql = mean(h_python - h_sql)
At generation time:
h' = h + alpha × v
alpha < 0: biases toward direct SQLalpha = 0: leaves the base model unchangedalpha > 0: biases toward Python database code
The most stable demonstration uses layer 16. The vector has 4,096 float32 components, matching the Qwen3-8B residual-stream width.
Contents
| Artifact | Purpose |
|---|---|
vectors/python_vs_sql_engineer_layer_{8,12,16,20,24,28}.pt |
Layer sweep of the primary Python-minus-SQL direction |
vectors/full_code_modality_layer_{12,16,20}.pt |
Broader fenced-code modality direction |
vectors/format_python.pt |
Python-versus-SQL formatting direction |
vectors/persona_executive.pt |
Executive-versus-engineer persona direction |
diagnostics/python_vs_sql_diagnostics.json |
Norms and within-pair cosine diagnostics |
config.json |
Machine-readable compatibility and intervention metadata |
Vector quality diagnostics
Four contrast pairs were used for the principal direction. Mean cosine alignment of each pair-specific difference with the mean vector remained high across the layer sweep:
| Layer | Vector norm | Mean pair cosine |
|---|---|---|
| 8 | 30.92 | 0.908 |
| 12 | 41.62 | 0.897 |
| 16 | 49.91 | 0.900 |
| 20 | 72.46 | 0.912 |
| 24 | 147.56 | 0.908 |
| 28 | 258.40 | 0.893 |
High alignment indicates a consistent contrast direction across the four examples; it does not by itself prove causal usefulness. Causal behavior is tested by intervening during generation and executing the resulting programs.
Minimal usage
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
base_model = "Qwen/Qwen3-8B"
artifact = torch.load(
"vectors/python_vs_sql_engineer_layer_16.pt",
map_location="cpu",
weights_only=True,
)
tokenizer = AutoTokenizer.from_pretrained(base_model)
model = AutoModelForCausalLM.from_pretrained(
base_model,
dtype=torch.bfloat16,
device_map="auto",
).eval()
layer = model.model.layers[artifact["layer"]]
vector = artifact["vector"].to(model.device, model.dtype)
alpha = 0.75 # positive -> Python; negative -> SQL
def steering_hook(_module, _inputs, output):
hidden = output[0] if isinstance(output, tuple) else output
steered = hidden.clone()
steered[:, -1, :] += alpha * vector
return (steered, *output[1:]) if isinstance(output, tuple) else steered
handle = layer.register_forward_hook(steering_hook)
try:
# Call model.generate(...) here.
pass
finally:
handle.remove()
Use the complete scripts and 100-table SQLite fixture in the linked dataset repository for reproducible prompts, schema retrieval, execution, and scoring.
Benchmark summary
The published 10-query benchmark covers joins across 2–6 tables. In the fast execution run:
- Negative/SQL generation executed successfully on 10/10 queries.
- Positive/Python generation executed successfully on 8/10 queries.
- SQL and Python results sometimes differed in row count or semantics even when both programs executed.
Execution success is therefore not semantic correctness. The repository keeps raw outputs and row counts visible so these differences can be audited.
Limitations
- Extracted from only four Python/SQL contrast pairs.
- Validated on one model family and checkpoint:
Qwen/Qwen3-8B. - Direction magnitude changes substantially with layer; alpha values are not directly comparable across layers.
- Forward hooks are implementation-specific and can break across model architecture changes.
- Steering changes probability distributions; it does not guarantee valid or safe code.
- Never execute generated database or Python code against production systems without sandboxing, validation, and authorization.
Related resources
- Downloads last month
- 18