wisent 0.5.6__py3-none-any.whl → 0.5.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of wisent might be problematic. Click here for more details.
- wisent/__init__.py +1 -1
- wisent/core/multi_steering.py +201 -205
- {wisent-0.5.6.dist-info → wisent-0.5.7.dist-info}/METADATA +1 -1
- {wisent-0.5.6.dist-info → wisent-0.5.7.dist-info}/RECORD +7 -7
- {wisent-0.5.6.dist-info → wisent-0.5.7.dist-info}/WHEEL +0 -0
- {wisent-0.5.6.dist-info → wisent-0.5.7.dist-info}/licenses/LICENSE +0 -0
- {wisent-0.5.6.dist-info → wisent-0.5.7.dist-info}/top_level.txt +0 -0
wisent/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.5.
|
|
1
|
+
__version__ = "0.5.7"
|
wisent/core/multi_steering.py
CHANGED
|
@@ -1,51 +1,18 @@
|
|
|
1
1
|
"""Multi-steering functionality for combining multiple steering vectors."""
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
4
5
|
import torch
|
|
5
|
-
from typing import
|
|
6
|
+
from typing import Iterable
|
|
6
7
|
from pathlib import Path
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
from .
|
|
12
|
-
|
|
13
|
-
# from .steering_methods.dac import DAC
|
|
14
|
-
from .utils.device import resolve_default_device
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
# Stub classes for missing modules
|
|
18
|
-
class Layer:
|
|
19
|
-
"""Stub Layer class - module doesn't exist in wisent package."""
|
|
20
|
-
def __init__(self, index: int):
|
|
21
|
-
self.index = index
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class Model:
|
|
25
|
-
"""Stub Model class - module doesn't exist in wisent package."""
|
|
26
|
-
def __init__(self, model_name: str, device: str = None):
|
|
27
|
-
self.model_name = model_name
|
|
28
|
-
self.device = device
|
|
29
|
-
# This is a stub - actual implementation would load the model
|
|
30
|
-
raise NotImplementedError("Model class not implemented in wisent package")
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class DAC:
|
|
34
|
-
"""Stub DAC class - module doesn't exist in wisent package."""
|
|
35
|
-
def __init__(self, device: str = None):
|
|
36
|
-
self.device = device
|
|
37
|
-
self.steering_vector = None
|
|
38
|
-
self.layer_index = None
|
|
39
|
-
self.is_trained = False
|
|
9
|
+
from wisent.core.models.wisent_model import WisentModel
|
|
10
|
+
from wisent.core.models.core.atoms import SteeringPlan
|
|
11
|
+
from wisent.core.activations.core.atoms import RawActivationMap
|
|
12
|
+
from wisent.core.prompts.core.atom import ChatMessage
|
|
13
|
+
from wisent.core.utils.device import resolve_default_device
|
|
40
14
|
|
|
41
|
-
|
|
42
|
-
def combine_steering_vectors(vectors, weights, normalize_weights=True):
|
|
43
|
-
"""Stub method for combining steering vectors."""
|
|
44
|
-
raise NotImplementedError("DAC steering method not implemented in wisent package")
|
|
45
|
-
|
|
46
|
-
def apply_steering(self, hidden_states, strength=1.0):
|
|
47
|
-
"""Stub method for applying steering."""
|
|
48
|
-
raise NotImplementedError("DAC steering method not implemented in wisent package")
|
|
15
|
+
__all__ = ["MultiSteering", "MultiSteeringError"]
|
|
49
16
|
|
|
50
17
|
|
|
51
18
|
class MultiSteeringError(Exception):
|
|
@@ -54,247 +21,271 @@ class MultiSteeringError(Exception):
|
|
|
54
21
|
|
|
55
22
|
|
|
56
23
|
class MultiSteering:
|
|
57
|
-
"""Handles multi-steering vector combination and application."""
|
|
58
|
-
|
|
24
|
+
"""Handles multi-steering vector combination and application using WisentModel."""
|
|
25
|
+
|
|
59
26
|
def __init__(self, device: str | None = None, method: str = "CAA"):
|
|
60
27
|
"""Initialize multi-steering handler.
|
|
61
|
-
|
|
28
|
+
|
|
62
29
|
Args:
|
|
63
30
|
device: Device to use for computations (cpu/cuda/mps)
|
|
64
|
-
method: Steering method to use for
|
|
31
|
+
method: Steering method to use (kept for backward compatibility, not used in new API)
|
|
65
32
|
"""
|
|
66
33
|
self.device = device or resolve_default_device()
|
|
67
|
-
self.method = method
|
|
68
|
-
self.loaded_vectors = []
|
|
69
|
-
self.weights = []
|
|
70
|
-
self.combined_vector = None
|
|
71
|
-
self.layer = None
|
|
72
|
-
|
|
73
|
-
def load_vectors(self, vector_specs:
|
|
34
|
+
self.method = method # Kept for backward compatibility
|
|
35
|
+
self.loaded_vectors: list[dict] = []
|
|
36
|
+
self.weights: list[float] = []
|
|
37
|
+
self.combined_vector: torch.Tensor | None = None
|
|
38
|
+
self.layer: int | None = None
|
|
39
|
+
|
|
40
|
+
def load_vectors(self, vector_specs: list[str]) -> None:
|
|
74
41
|
"""Load and validate steering vectors from file paths.
|
|
75
|
-
|
|
42
|
+
|
|
76
43
|
Args:
|
|
77
44
|
vector_specs: List of "path:weight" specifications
|
|
78
|
-
|
|
45
|
+
|
|
79
46
|
Raises:
|
|
80
47
|
MultiSteeringError: If vectors cannot be loaded or are incompatible
|
|
81
48
|
"""
|
|
82
49
|
if not vector_specs:
|
|
83
50
|
raise MultiSteeringError("No vectors specified")
|
|
84
|
-
|
|
51
|
+
|
|
85
52
|
self.loaded_vectors = []
|
|
86
53
|
self.weights = []
|
|
87
54
|
layers_found = set()
|
|
88
|
-
|
|
55
|
+
|
|
89
56
|
for spec in vector_specs:
|
|
90
57
|
parts = spec.split(":")
|
|
91
58
|
if len(parts) != 2:
|
|
92
59
|
raise MultiSteeringError(f"Invalid vector specification: {spec}. Expected format: path:weight")
|
|
93
|
-
|
|
60
|
+
|
|
94
61
|
vector_path = parts[0]
|
|
95
62
|
try:
|
|
96
63
|
weight = float(parts[1])
|
|
97
64
|
except ValueError:
|
|
98
65
|
raise MultiSteeringError(f"Invalid weight in {spec}. Must be a number.")
|
|
99
|
-
|
|
66
|
+
|
|
100
67
|
if not Path(vector_path).exists():
|
|
101
68
|
raise MultiSteeringError(f"Vector file not found: {vector_path}")
|
|
102
|
-
|
|
69
|
+
|
|
103
70
|
print(f"Loading vector from {vector_path} with weight {weight}")
|
|
104
|
-
|
|
71
|
+
|
|
105
72
|
try:
|
|
106
|
-
vector_data = torch.load(vector_path, map_location=self.device)
|
|
73
|
+
vector_data = torch.load(vector_path, map_location=self.device, weights_only=False)
|
|
107
74
|
except Exception as e:
|
|
108
75
|
raise MultiSteeringError(f"Failed to load vector from {vector_path}: {e}")
|
|
109
|
-
|
|
76
|
+
|
|
110
77
|
# Extract metadata from loaded vector
|
|
111
78
|
if isinstance(vector_data, dict):
|
|
112
79
|
layer = vector_data.get("layer_index", None)
|
|
113
80
|
steering_vector = vector_data.get("steering_vector", None)
|
|
114
|
-
|
|
81
|
+
|
|
115
82
|
if steering_vector is None:
|
|
116
83
|
raise MultiSteeringError(f"No steering vector found in {vector_path}")
|
|
117
|
-
|
|
84
|
+
|
|
118
85
|
if layer is not None:
|
|
119
86
|
layers_found.add(layer)
|
|
120
|
-
|
|
87
|
+
|
|
121
88
|
self.loaded_vectors.append(vector_data)
|
|
122
89
|
self.weights.append(weight)
|
|
123
|
-
|
|
90
|
+
|
|
124
91
|
print(f" ✓ Loaded vector from layer {layer}")
|
|
125
92
|
else:
|
|
126
93
|
raise MultiSteeringError(f"Invalid vector format in {vector_path}")
|
|
127
|
-
|
|
94
|
+
|
|
128
95
|
# Validate compatibility
|
|
129
96
|
if len(layers_found) > 1:
|
|
130
97
|
raise MultiSteeringError(f"Vectors from different layers cannot be combined: {layers_found}")
|
|
131
|
-
|
|
98
|
+
|
|
132
99
|
if not layers_found:
|
|
133
100
|
raise MultiSteeringError("No layer information found in vectors")
|
|
134
|
-
|
|
135
|
-
self.layer =
|
|
136
|
-
|
|
101
|
+
|
|
102
|
+
self.layer = list(layers_found)[0]
|
|
103
|
+
|
|
137
104
|
print(f"\nUsing {self.method} method for vector combination")
|
|
138
|
-
print(f"Target layer: {self.layer
|
|
139
|
-
|
|
105
|
+
print(f"Target layer: {self.layer}")
|
|
106
|
+
|
|
140
107
|
def combine_vectors(self, normalize: bool = True) -> torch.Tensor:
|
|
141
|
-
"""Combine loaded vectors using
|
|
142
|
-
|
|
108
|
+
"""Combine loaded vectors using SteeringPlan.
|
|
109
|
+
|
|
143
110
|
Args:
|
|
144
111
|
normalize: Whether to normalize the combined vector
|
|
145
|
-
|
|
112
|
+
|
|
146
113
|
Returns:
|
|
147
114
|
Combined steering vector as tensor
|
|
148
|
-
|
|
115
|
+
|
|
149
116
|
Raises:
|
|
150
117
|
MultiSteeringError: If combination fails
|
|
151
118
|
"""
|
|
152
119
|
if not self.loaded_vectors:
|
|
153
120
|
raise MultiSteeringError("No vectors loaded")
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
steering_vector = steering_vector.to(self.device)
|
|
191
|
-
|
|
192
|
-
vectors.append(steering_vector)
|
|
193
|
-
|
|
194
|
-
# Use DAC's static method for combination
|
|
195
|
-
self.combined_vector = DAC.combine_steering_vectors(
|
|
196
|
-
vectors, self.weights, normalize_weights=normalize
|
|
197
|
-
)
|
|
198
|
-
|
|
121
|
+
|
|
122
|
+
if self.layer is None:
|
|
123
|
+
raise MultiSteeringError("No layer information available")
|
|
124
|
+
|
|
125
|
+
print(f"\n🔄 Combining {len(self.loaded_vectors)} vectors")
|
|
126
|
+
|
|
127
|
+
# Build RawActivationMap for each vector
|
|
128
|
+
raw_maps: list[RawActivationMap] = []
|
|
129
|
+
for vector_data in self.loaded_vectors:
|
|
130
|
+
steering_vector = vector_data["steering_vector"]
|
|
131
|
+
|
|
132
|
+
if not isinstance(steering_vector, torch.Tensor):
|
|
133
|
+
steering_vector = torch.tensor(steering_vector, device=self.device)
|
|
134
|
+
else:
|
|
135
|
+
steering_vector = steering_vector.to(self.device)
|
|
136
|
+
|
|
137
|
+
# Create a map with layer name as string (required by SteeringPlan)
|
|
138
|
+
raw_map: RawActivationMap = {str(self.layer): steering_vector}
|
|
139
|
+
raw_maps.append(raw_map)
|
|
140
|
+
|
|
141
|
+
# Create SteeringPlan with weighted combination
|
|
142
|
+
plan = SteeringPlan.from_raw(
|
|
143
|
+
raw=raw_maps,
|
|
144
|
+
weights=self.weights,
|
|
145
|
+
scale=1.0,
|
|
146
|
+
normalize=normalize
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# Extract the combined vector from the plan
|
|
150
|
+
layer_str = str(self.layer)
|
|
151
|
+
if layer_str not in plan.layers:
|
|
152
|
+
raise MultiSteeringError(f"Layer {self.layer} not found in steering plan")
|
|
153
|
+
|
|
154
|
+
steering_vector = plan.layers[layer_str]
|
|
155
|
+
self.combined_vector = steering_vector.vector
|
|
156
|
+
|
|
199
157
|
print(f" ✓ Combined vector shape: {self.combined_vector.shape}")
|
|
200
158
|
print(f" ✓ Combined vector norm: {torch.norm(self.combined_vector).item():.4f}")
|
|
201
|
-
|
|
159
|
+
|
|
202
160
|
return self.combined_vector
|
|
203
|
-
|
|
204
|
-
def
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
161
|
+
|
|
162
|
+
def apply_steering_stream(
|
|
163
|
+
self,
|
|
164
|
+
model: WisentModel,
|
|
165
|
+
prompt: str,
|
|
166
|
+
max_new_tokens: int = 100,
|
|
167
|
+
temperature: float = 0.7,
|
|
168
|
+
top_p: float = 0.9
|
|
169
|
+
) -> Iterable[str]:
|
|
170
|
+
"""Apply the combined steering vector to generate text with streaming.
|
|
171
|
+
|
|
172
|
+
Args:
|
|
173
|
+
model: WisentModel instance to use for generation
|
|
174
|
+
prompt: Input prompt
|
|
175
|
+
max_new_tokens: Maximum tokens to generate
|
|
176
|
+
temperature: Sampling temperature
|
|
177
|
+
top_p: Top-p sampling parameter
|
|
178
|
+
|
|
179
|
+
Yields:
|
|
180
|
+
Generated text chunks
|
|
181
|
+
|
|
182
|
+
Raises:
|
|
183
|
+
MultiSteeringError: If steering fails
|
|
184
|
+
"""
|
|
185
|
+
if self.combined_vector is None:
|
|
186
|
+
raise MultiSteeringError("No combined vector available. Call combine_vectors() first.")
|
|
187
|
+
|
|
188
|
+
if self.layer is None:
|
|
189
|
+
raise MultiSteeringError("No layer information available")
|
|
190
|
+
|
|
191
|
+
print(f"\n🎯 Applying combined steering vector at layer {self.layer}")
|
|
192
|
+
print(f"Prompt: {prompt}")
|
|
193
|
+
print("=" * 50)
|
|
194
|
+
|
|
195
|
+
# Create SteeringPlan from the combined vector
|
|
196
|
+
raw_map: RawActivationMap = {str(self.layer): self.combined_vector}
|
|
197
|
+
steering_plan = SteeringPlan.from_raw(
|
|
198
|
+
raw=raw_map,
|
|
199
|
+
scale=1.0,
|
|
200
|
+
normalize=False # Already normalized in combine_vectors
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
# Format prompt as chat messages
|
|
204
|
+
messages: list[ChatMessage] = [{"role": "user", "content": prompt}]
|
|
205
|
+
|
|
206
|
+
try:
|
|
207
|
+
# Use WisentModel's generate_stream with steering
|
|
208
|
+
yield from model.generate_stream(
|
|
209
|
+
inputs=[messages],
|
|
210
|
+
max_new_tokens=max_new_tokens,
|
|
211
|
+
temperature=temperature,
|
|
212
|
+
top_p=top_p,
|
|
213
|
+
use_steering=True,
|
|
214
|
+
steering_plan=steering_plan,
|
|
215
|
+
skip_prompt=True,
|
|
216
|
+
skip_special_tokens=True
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
except Exception as e:
|
|
220
|
+
raise MultiSteeringError(f"Failed to apply steering: {e}")
|
|
221
|
+
|
|
222
|
+
def apply_steering(
|
|
223
|
+
self,
|
|
224
|
+
model: WisentModel,
|
|
225
|
+
prompt: str,
|
|
226
|
+
max_new_tokens: int = 100,
|
|
227
|
+
temperature: float = 0.7,
|
|
228
|
+
top_p: float = 0.9
|
|
229
|
+
) -> str:
|
|
230
|
+
"""Apply the combined steering vector to generate text (non-streaming).
|
|
231
|
+
|
|
208
232
|
Args:
|
|
209
|
-
model:
|
|
233
|
+
model: WisentModel instance to use for generation
|
|
210
234
|
prompt: Input prompt
|
|
211
235
|
max_new_tokens: Maximum tokens to generate
|
|
212
236
|
temperature: Sampling temperature
|
|
213
237
|
top_p: Top-p sampling parameter
|
|
214
|
-
|
|
238
|
+
|
|
215
239
|
Returns:
|
|
216
240
|
Generated text
|
|
217
|
-
|
|
241
|
+
|
|
218
242
|
Raises:
|
|
219
243
|
MultiSteeringError: If steering fails
|
|
220
244
|
"""
|
|
221
245
|
if self.combined_vector is None:
|
|
222
246
|
raise MultiSteeringError("No combined vector available. Call combine_vectors() first.")
|
|
223
|
-
|
|
247
|
+
|
|
224
248
|
if self.layer is None:
|
|
225
249
|
raise MultiSteeringError("No layer information available")
|
|
226
|
-
|
|
227
|
-
print(f"\n🎯 Applying combined steering vector at layer {self.layer
|
|
250
|
+
|
|
251
|
+
print(f"\n🎯 Applying combined steering vector at layer {self.layer}")
|
|
228
252
|
print(f"Prompt: {prompt}")
|
|
229
253
|
print("=" * 50)
|
|
230
|
-
|
|
231
|
-
# Create
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
steering_method.is_trained = True
|
|
243
|
-
|
|
244
|
-
# Set up steering hook
|
|
245
|
-
hooks = []
|
|
246
|
-
|
|
247
|
-
def steering_hook(module, input, output):
|
|
248
|
-
if isinstance(output, tuple):
|
|
249
|
-
hidden_states = output[0]
|
|
250
|
-
else:
|
|
251
|
-
hidden_states = output
|
|
252
|
-
|
|
253
|
-
# Apply steering using the method's apply_steering
|
|
254
|
-
steered = steering_method.apply_steering(hidden_states, strength=1.0)
|
|
255
|
-
|
|
256
|
-
if isinstance(output, tuple):
|
|
257
|
-
return (steered,) + output[1:]
|
|
258
|
-
return steered
|
|
259
|
-
|
|
260
|
-
# Find the target layer module
|
|
261
|
-
if hasattr(model.hf_model, "model") and hasattr(model.hf_model.model, "layers"):
|
|
262
|
-
layer_module = model.hf_model.model.layers[self.layer.index]
|
|
263
|
-
elif hasattr(model.hf_model, "transformer") and hasattr(model.hf_model.transformer, "h"):
|
|
264
|
-
layer_module = model.hf_model.transformer.h[self.layer.index]
|
|
265
|
-
else:
|
|
266
|
-
raise MultiSteeringError("Could not find model layers")
|
|
267
|
-
|
|
268
|
-
# Register hook
|
|
269
|
-
handle = layer_module.register_forward_hook(steering_hook)
|
|
270
|
-
hooks.append(handle)
|
|
271
|
-
|
|
254
|
+
|
|
255
|
+
# Create SteeringPlan from the combined vector
|
|
256
|
+
raw_map: RawActivationMap = {str(self.layer): self.combined_vector}
|
|
257
|
+
steering_plan = SteeringPlan.from_raw(
|
|
258
|
+
raw=raw_map,
|
|
259
|
+
scale=1.0,
|
|
260
|
+
normalize=False # Already normalized in combine_vectors
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
# Format prompt as chat messages
|
|
264
|
+
messages: list[ChatMessage] = [{"role": "user", "content": prompt}]
|
|
265
|
+
|
|
272
266
|
try:
|
|
273
|
-
#
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
layer_index=self.layer.index,
|
|
267
|
+
# Use WisentModel's generate with steering
|
|
268
|
+
outputs = model.generate(
|
|
269
|
+
inputs=[messages],
|
|
277
270
|
max_new_tokens=max_new_tokens,
|
|
278
271
|
temperature=temperature,
|
|
279
272
|
top_p=top_p,
|
|
273
|
+
use_steering=True,
|
|
274
|
+
steering_plan=steering_plan
|
|
280
275
|
)
|
|
281
|
-
|
|
282
|
-
return
|
|
283
|
-
|
|
276
|
+
|
|
277
|
+
return outputs[0] if outputs else ""
|
|
278
|
+
|
|
284
279
|
except Exception as e:
|
|
285
280
|
raise MultiSteeringError(f"Failed to apply steering: {e}")
|
|
286
|
-
finally:
|
|
287
|
-
# Clean up hooks
|
|
288
|
-
for hook in hooks:
|
|
289
|
-
hook.remove()
|
|
290
281
|
|
|
291
282
|
|
|
292
283
|
def run_multi_steer(
|
|
293
|
-
vector_specs:
|
|
284
|
+
vector_specs: list[str],
|
|
294
285
|
model_name: str,
|
|
295
286
|
prompt: str,
|
|
296
287
|
method: str = "CAA",
|
|
297
|
-
layer:
|
|
288
|
+
layer: int | None = None,
|
|
298
289
|
max_new_tokens: int = 100,
|
|
299
290
|
temperature: float = 0.7,
|
|
300
291
|
top_p: float = 0.9,
|
|
@@ -302,45 +293,50 @@ def run_multi_steer(
|
|
|
302
293
|
verbose: bool = True,
|
|
303
294
|
) -> str:
|
|
304
295
|
"""Convenience function to run multi-steering.
|
|
305
|
-
|
|
296
|
+
|
|
306
297
|
Args:
|
|
307
298
|
vector_specs: List of "path:weight" specifications
|
|
308
299
|
model_name: Name of model to load
|
|
309
300
|
prompt: Input prompt
|
|
310
|
-
method: Steering method to use (
|
|
301
|
+
method: Steering method to use (kept for backward compatibility)
|
|
311
302
|
layer: Target layer (will be inferred from vectors if not specified)
|
|
312
303
|
max_new_tokens: Maximum tokens to generate
|
|
313
|
-
temperature: Sampling temperature
|
|
304
|
+
temperature: Sampling temperature
|
|
314
305
|
top_p: Top-p sampling parameter
|
|
315
306
|
device: Device to use
|
|
316
307
|
verbose: Whether to print progress
|
|
317
|
-
|
|
308
|
+
|
|
318
309
|
Returns:
|
|
319
310
|
Generated text
|
|
320
311
|
"""
|
|
321
312
|
# Initialize model
|
|
322
313
|
if verbose:
|
|
323
314
|
print(f"\n🚀 Loading model: {model_name}")
|
|
324
|
-
|
|
315
|
+
|
|
325
316
|
chosen_device = device or resolve_default_device()
|
|
326
|
-
|
|
327
|
-
|
|
317
|
+
|
|
318
|
+
# Load model using WisentModel
|
|
319
|
+
model = WisentModel(
|
|
320
|
+
model_name=model_name,
|
|
321
|
+
device=chosen_device
|
|
322
|
+
)
|
|
323
|
+
|
|
328
324
|
# Initialize multi-steering with specified method
|
|
329
325
|
multi_steer = MultiSteering(device=chosen_device, method=method)
|
|
330
|
-
|
|
326
|
+
|
|
331
327
|
# Load vectors
|
|
332
328
|
multi_steer.load_vectors(vector_specs)
|
|
333
|
-
|
|
329
|
+
|
|
334
330
|
# Override layer if specified
|
|
335
331
|
if layer is not None:
|
|
336
|
-
multi_steer.layer =
|
|
332
|
+
multi_steer.layer = layer
|
|
337
333
|
if verbose:
|
|
338
334
|
print(f"Overriding layer to: {layer}")
|
|
339
|
-
|
|
335
|
+
|
|
340
336
|
# Combine vectors with normalization
|
|
341
337
|
multi_steer.combine_vectors(normalize=True)
|
|
342
|
-
|
|
343
|
-
# Apply steering
|
|
338
|
+
|
|
339
|
+
# Apply steering (non-streaming)
|
|
344
340
|
output = multi_steer.apply_steering(
|
|
345
341
|
model=model,
|
|
346
342
|
prompt=prompt,
|
|
@@ -348,5 +344,5 @@ def run_multi_steer(
|
|
|
348
344
|
temperature=temperature,
|
|
349
345
|
top_p=top_p
|
|
350
346
|
)
|
|
351
|
-
|
|
352
|
-
return output
|
|
347
|
+
|
|
348
|
+
return output
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
wisent/__init__.py,sha256=
|
|
1
|
+
wisent/__init__.py,sha256=KiyyYbyEe0O858kmiWcg1RdmqGUYtk_JqRmc3_Ev2Q8,22
|
|
2
2
|
wisent/benchmarks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
wisent/benchmarks/coding/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
wisent/benchmarks/coding/metrics/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -64,7 +64,7 @@ wisent/core/managed_cached_benchmarks.py,sha256=JbvpZ1fgSuQQhyQVKEvqrQZRHGqfnjo9
|
|
|
64
64
|
wisent/core/mixed_benchmark_sampler.py,sha256=tKQCHUXVuYeCyx4VZt8O1hGyB-TOY_SQ_SYi8cyApII,13585
|
|
65
65
|
wisent/core/model_config_manager.py,sha256=rQAdSmk3GFlZXyHp3fSV1bORxiZWhmzIz1uo3H4JtkA,12009
|
|
66
66
|
wisent/core/model_persistence.py,sha256=6_vc1Ndujd4v0O68giINSTvYhmb7-AiacWwAbqLOrls,10636
|
|
67
|
-
wisent/core/multi_steering.py,sha256=
|
|
67
|
+
wisent/core/multi_steering.py,sha256=9HpI-4jL9PYAxp-4QrL47FYAapDGMDmnZB-RvHz7cNo,11729
|
|
68
68
|
wisent/core/parser.py,sha256=_YDeSuQMx0zNknz9rX3Ls1YPT1x5eohoY8rfjeoqxV8,69091
|
|
69
69
|
wisent/core/representation.py,sha256=hBl_N9qbr5Gsa7GCQ0nMWRm82RqYEfhd9cyf0PPH5LY,195
|
|
70
70
|
wisent/core/sample_size_optimizer.py,sha256=6wegGXZpdGpiR4R0YJ1D2JqLr6yinMndEx2gB5FL80s,23666
|
|
@@ -213,8 +213,8 @@ wisent/synthetic/generators/diversities/core/__init__.py,sha256=47DEQpj8HBSa-_TI
|
|
|
213
213
|
wisent/synthetic/generators/diversities/core/core.py,sha256=TjSj5T7NE5kRH-ABcFqb1Hz_j3Z6F_TcV-95uHD5Xw8,2201
|
|
214
214
|
wisent/synthetic/generators/diversities/methods/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
215
215
|
wisent/synthetic/generators/diversities/methods/fast_diversity.py,sha256=Z2UzTbzyJFM_ToxCoXM_LQQQ1Jc6BZknrbpikTG1MRw,8522
|
|
216
|
-
wisent-0.5.
|
|
217
|
-
wisent-0.5.
|
|
218
|
-
wisent-0.5.
|
|
219
|
-
wisent-0.5.
|
|
220
|
-
wisent-0.5.
|
|
216
|
+
wisent-0.5.7.dist-info/licenses/LICENSE,sha256=wy0iaw8b2tyqZAfKHib3lP3PJ9o88FDCg92oUHh3sDQ,1073
|
|
217
|
+
wisent-0.5.7.dist-info/METADATA,sha256=k6ECqqwEDcxK7hySjeY43r5v49fWesosVA-Y7vD4eVE,2424
|
|
218
|
+
wisent-0.5.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
219
|
+
wisent-0.5.7.dist-info/top_level.txt,sha256=2Ts9Iyldnb3auIN2HBBaHPknRy7nSRDm2f6RGzYgr8A,7
|
|
220
|
+
wisent-0.5.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|