Mihai Chirculescu commited on
Commit ·
5195c1d
1
Parent(s): 762b54a
Revert "Add Qwen 0.8 3.5"
Browse filesThis reverts commit 762b54a0a7c471930f8a8d966027031e1d7097f0.
- README.md +1 -4
- app.py +4 -44
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -11,7 +11,4 @@ license: mit
|
|
| 11 |
short_description: Steer LLMs with activation vectors
|
| 12 |
---
|
| 13 |
|
| 14 |
-
An interactive Gradio demo that lets you steer local models using activation vectors.
|
| 15 |
-
Included model options: `LiquidAI/LFM2-350M`, `LiquidAI/LFM2-700M`, `LiquidAI/LFM2-1.2B`, and `Qwen/Qwen3.5-0.8B`.
|
| 16 |
-
|
| 17 |
-
For `Qwen/Qwen3.5-0.8B`, use a recent `transformers` version that recognizes the `qwen3_5` architecture.
|
|
|
|
| 11 |
short_description: Steer LLMs with activation vectors
|
| 12 |
---
|
| 13 |
|
| 14 |
+
An interactive Gradio demo that lets you steer two local models using activation vectors on layer 8. Models: LiquidAI/LFM2-350M and unsloth/Llama-3.2-1B-Instruct. Add one or more vectors with coefficients, pick the model, and chat with the steered output.
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -8,12 +8,7 @@ import torch
|
|
| 8 |
from llm_steer import Steer, DecaySchedule
|
| 9 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 10 |
|
| 11 |
-
MODEL_IDS = [
|
| 12 |
-
"LiquidAI/LFM2-350M",
|
| 13 |
-
"LiquidAI/LFM2-700M",
|
| 14 |
-
"LiquidAI/LFM2-1.2B",
|
| 15 |
-
"Qwen/Qwen3.5-0.8B",
|
| 16 |
-
]
|
| 17 |
DEFAULT_SCHEDULE_ENABLED = True
|
| 18 |
DEFAULT_SCHEDULE_RATE = 0.85
|
| 19 |
DEFAULT_SCHEDULE_MIN_MULTIPLIER = 0.35
|
|
@@ -96,34 +91,7 @@ def _load_model(model_id: str) -> ModelBundle:
|
|
| 96 |
)
|
| 97 |
|
| 98 |
|
| 99 |
-
MODELS:
|
| 100 |
-
MODEL_LOAD_LOCK = threading.Lock()
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
def _get_model_bundle(model_id: str) -> ModelBundle:
|
| 104 |
-
bundle = MODELS.get(model_id)
|
| 105 |
-
if bundle is not None:
|
| 106 |
-
return bundle
|
| 107 |
-
with MODEL_LOAD_LOCK:
|
| 108 |
-
bundle = MODELS.get(model_id)
|
| 109 |
-
if bundle is None:
|
| 110 |
-
bundle = _load_model(model_id)
|
| 111 |
-
MODELS[model_id] = bundle
|
| 112 |
-
return bundle
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
def _format_model_load_error(model_id: str, exc: Exception) -> str:
|
| 116 |
-
reason = str(exc).strip()
|
| 117 |
-
if "does not recognize this architecture" in reason:
|
| 118 |
-
return (
|
| 119 |
-
f"Could not load {model_id}. "
|
| 120 |
-
"Your installed `transformers` version is too old for this model. "
|
| 121 |
-
"Upgrade `transformers` and retry."
|
| 122 |
-
)
|
| 123 |
-
if reason:
|
| 124 |
-
first_line = reason.splitlines()[0].strip()
|
| 125 |
-
return f"Could not load {model_id}: {first_line}"
|
| 126 |
-
return f"Could not load {model_id}."
|
| 127 |
|
| 128 |
|
| 129 |
def _parse_vectors(
|
|
@@ -255,15 +223,7 @@ def respond(
|
|
| 255 |
if not message:
|
| 256 |
return history, ""
|
| 257 |
|
| 258 |
-
|
| 259 |
-
bundle = _get_model_bundle(model_id)
|
| 260 |
-
except Exception as exc:
|
| 261 |
-
updated_history = history + [
|
| 262 |
-
{"role": "user", "content": message},
|
| 263 |
-
{"role": "assistant", "content": _format_model_load_error(model_id, exc)},
|
| 264 |
-
]
|
| 265 |
-
return updated_history, ""
|
| 266 |
-
|
| 267 |
steer_vectors = _parse_vectors(vectors)
|
| 268 |
schedule = None
|
| 269 |
if vectors_enabled and schedule_enabled:
|
|
@@ -417,7 +377,7 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
| 417 |
)
|
| 418 |
add_vector = gr.Button("Add new vector row")
|
| 419 |
gr.Markdown(
|
| 420 |
-
"Coeff can be negative. Layer
|
| 421 |
)
|
| 422 |
with gr.Accordion(
|
| 423 |
"Steering schedule",
|
|
|
|
| 8 |
from llm_steer import Steer, DecaySchedule
|
| 9 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 10 |
|
| 11 |
+
MODEL_IDS = ["LiquidAI/LFM2-350M", "LiquidAI/LFM2-700M", "LiquidAI/LFM2-1.2B"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
DEFAULT_SCHEDULE_ENABLED = True
|
| 13 |
DEFAULT_SCHEDULE_RATE = 0.85
|
| 14 |
DEFAULT_SCHEDULE_MIN_MULTIPLIER = 0.35
|
|
|
|
| 91 |
)
|
| 92 |
|
| 93 |
|
| 94 |
+
MODELS = {model_id: _load_model(model_id) for model_id in MODEL_IDS}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
|
| 97 |
def _parse_vectors(
|
|
|
|
| 223 |
if not message:
|
| 224 |
return history, ""
|
| 225 |
|
| 226 |
+
bundle = MODELS[model_id]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
steer_vectors = _parse_vectors(vectors)
|
| 228 |
schedule = None
|
| 229 |
if vectors_enabled and schedule_enabled:
|
|
|
|
| 377 |
)
|
| 378 |
add_vector = gr.Button("Add new vector row")
|
| 379 |
gr.Markdown(
|
| 380 |
+
"Coeff can be negative. Layer should have value between 0 and 15."
|
| 381 |
)
|
| 382 |
with gr.Accordion(
|
| 383 |
"Steering schedule",
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
llm_steer >= 2.0.1
|
| 2 |
-
transformers
|
| 3 |
torch
|
| 4 |
accelerate
|
| 5 |
sentencepiece
|
|
|
|
| 1 |
llm_steer >= 2.0.1
|
| 2 |
+
transformers
|
| 3 |
torch
|
| 4 |
accelerate
|
| 5 |
sentencepiece
|