PASTA
steerability.algorithms.state_control.pasta
args
control
SUPPORTED_ATTN_IMPLEMENTATIONS = ('eager', 'sdpa')
module-attribute
logger = logging.getLogger(__name__)
module-attribute
PASTA
Bases: HookControl
Implementation of PASTA (Post-hoc Attention STeering Approach) from Zhang et al., 2023.
PASTA performs controlled text generation by dynamically modifying attention patterns during inference to amplify or suppress the influence of specific text spans. This allows for fine-grained steering of model behavior without requiring model retraining or parameter updates.
The algorithm works by:
-
Substring Identification: Locate target substrings within the input prompt using tokenizer offset mapping to determine precise token ranges.
-
Attention Modification: Inject scaling factors into the attention mask of specified layers and heads to increase or decrease attention weights for the identified token ranges.
-
Dynamic Steering: Apply different scaling strategies (include, exclude, or generation-focused) to control how the model attends to relevant spans during text generation.
This approach enables real-time control over model focus and can be used for tasks like concept amplification, bias mitigation, or content filtering without architectural changes.
The head_config argument accepts a dict (layer index to head indices), a list (layer indices,
all heads), or a HeadProfile recipe. A HeadProfile moves the paper's one-time head-profiling
stage into steer(): each candidate head is steered on its own on a task-agnostic set of
profiling prompts, scored by a SampleScorer, and ranked by the paired lift over an unsteered
baseline; the selected heads become the dict head map, and the resolution is available as
head_profile (a HeadProfileResult). Profiling runs on the live model through the pipeline's
session, and the resolved head map freezes into a .spipe as a plain-dict PASTA.
Note
PASTA injects a 4D additive attention mask, which only the "eager" and "sdpa" attention
implementations consume. Load the model with attn_implementation="eager" (or "sdpa");
"flash_attention_2" expects a 2D padding mask and silently ignores or errors on the
injected scaling. steer() fails fast if the model reports an unsupported implementation.
Reference: - "PASTA: Tell Your Model Where to Attend: Post-hoc Attention Steering for LLMs" Qingru Zhang, Chandan Singh, Liyuan Liu, Xiaodong Liu, Bin Yu, Jianfeng Gao, Tuo Zhao https://arxiv.org/abs/2311.02262
Source code in steerability/algorithms/state_control/pasta/control.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 | |
RUNTIME_KWARGS_SCHEMA = [{'name': 'substrings', 'type': 'list[str]', 'required': True, 'scope': 'row', 'help': "Substrings whose attention should be steered. Required at inference time. A `str` broadcasts to every row; a `list[list[str]]` of batch length carries one group per row; a flat `list[str]` is accepted only at batch size 1, as that row's group."}]
class-attribute
instance-attribute
args = self.Args.validate(*args, **kwargs)
instance-attribute
device = None
class-attribute
instance-attribute
enabled = True
class-attribute
instance-attribute
head_profile = None
class-attribute
instance-attribute
model = None
class-attribute
instance-attribute
supports_batching = True
class-attribute
instance-attribute
tokenizer = None
class-attribute
instance-attribute
attention_layers()
The model's attention layers, ascending (available after steer()).
Source code in steerability/algorithms/state_control/pasta/control.py
373 374 375 | |
build_hooks_for(token_ranges, input_len, head_map, alpha)
Assemble the pre-hook dict for a head map at a strength, from located spans.
The log-alpha constant is bound into each pre-hook partial, so a profiling strength and
the control's own alpha never cross. Only "pre" hooks are populated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_ranges
|
list[Tensor]
|
Located spans, one |
required |
input_len
|
int
|
The sequence length the ranges were located in. |
required |
head_map
|
dict[int, list[int]]
|
Layer index to head indices to steer. |
required |
alpha
|
float
|
The emphasis strength for this hook set. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list]
|
Hook specifications with |
Source code in steerability/algorithms/state_control/pasta/control.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
cleanup()
Release resources allocated during steer().
Override in subclasses that allocate GPU memory or other resources during steering. Default no-op.
Source code in steerability/algorithms/core/base_control.py
195 196 197 198 199 200 201 | |
clone_for_call(seed=None)
A configuration-preserving shallow clone for one generation call.
The clone shares steer-time artifacts (memories, steering vectors, attached tokenizers)
with the original but has its own attribute namespace, so per-call attribute mutation on
the clone never races another call using the original. When seed is given and the
control defines reseed(seed), the clone's client-side RNG is re-seeded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
int | None
|
Optional seed forwarded to the clone's |
None
|
Returns:
| Type | Description |
|---|---|
BaseControl
|
The clone. |
Source code in steerability/algorithms/core/base_control.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
export_intervention_spec(runtime_kwargs=None)
The control's InterventionSpec for intervention-capable backends, or None.
The spec is the second serialization of the tuple the control's hooks close over,
emitted from the same transform, gate, and scope objects. Must be called after
steer(). Returns None when the configuration has no wire form (the configuration is
then hook-only) or when the control does not implement spec export at all.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runtime_kwargs
|
dict | None
|
Per-call parameters, mirroring |
None
|
Returns:
| Type | Description |
|---|---|
InterventionSpec | None
|
The validated |
Source code in steerability/algorithms/state_control/base.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
export_state()
The resolved profile's lift grid under "head_profile" (after a profiled steer()).
Empty for a dict or list head map, or before steer() resolves a HeadProfile. The full
HeadProfileResult is not serialized here; it stays on head_profile and the caller
writes it through HeadProfileResult.save.
Source code in steerability/algorithms/state_control/pasta/control.py
392 393 394 395 396 397 398 399 400 401 | |
fit_identity()
The fit-relevant recipe inputs for staleness detection, or None.
For a HeadProfile head map, the profile's fit_ingredients() together with the
control's scale_position (the profile is scored under it). None for a dict or list head
map. The control's own alpha is an application parameter and is excluded.
Source code in steerability/algorithms/state_control/pasta/control.py
419 420 421 422 423 424 425 426 427 428 | |
frozen_form(state)
A same-class state_control/pasta frozen form carrying the resolved dict head map.
Only used when head_config is a HeadProfile; a dict or list head map keeps the
BaseControl default (the recipe is the frozen form). The loaded control is a plain-dict
PASTA whose steer() does no rollouts.
Source code in steerability/algorithms/state_control/pasta/control.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | |
get_hooks(input_ids, runtime_kwargs, **__)
Create attention modification hooks for specified substrings.
Identifies token ranges corresponding to target substrings and prepares hooks that will modify attention weights
during the forward pass, at the configured head map and the control's alpha.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Tensor
|
Input token IDs of shape [batch_size, seq_len]. |
required |
runtime_kwargs
|
dict | None
|
Must contain "substrings" key with target text spans:
|
required |
Returns:
| Type | Description |
|---|---|
dict[str, list]
|
dict[str, list]: Hook specifications with "pre", "forward", "backward" keys. Only "pre" hooks are populated for attention modification. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If "substrings" is missing from runtime_kwargs, a flat list of strings is
passed at batch size > 1, a group is a |
Source code in steerability/algorithms/state_control/pasta/control.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
locate_spans(input_ids, substrings)
Locate the substrings spans in input_ids, in the tensor's own coordinates.
Runs the substring-to-token-range resolution once for a prepared batch, so a caller
steering many head maps over one batch (head profiling) locates the spans once and only
reassembles the hook dict per candidate. The returned ranges are in the coordinate system
of input_ids (its key axis includes any BOS/template and left-pad tokens).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Tensor
|
Prompt token ids of shape |
required |
substrings
|
The |
required |
Returns:
| Type | Description |
|---|---|
list[Tensor]
|
A |
int
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in steerability/algorithms/state_control/pasta/control.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
num_heads_of_layer(layer)
The attention head count of layer (available after steer()).
Source code in steerability/algorithms/state_control/pasta/control.py
377 378 379 | |
requirements()
Backend requirements for attention-map editing.
PASTA writes into attention maps through torch hooks, which fused paged-attention
kernels never materialize, so the generate phase requires Capability.IN_PROCESS_TORCH.
The spec constraint reports a configured incompatible attention implementation
(hf_model_kwargs["attn_implementation"] outside "eager"/"sdpa") at check() time,
before any model loads; the same condition is re-checked against the live model in
steer().
Returns:
| Type | Description |
|---|---|
Requirements
|
The control's phase-keyed requirements. |
Source code in steerability/algorithms/state_control/pasta/control.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
steer(model, tokenizer=None, session=None, **__)
Initialize PASTA by configuring attention head mappings and model references.
Resolves the attention module path and head count of every attention layer of the model,
resolves a HeadProfile head map when head_config is a profiling recipe (steering each
candidate head through the pipeline's session), sets up the resolved head map, and fails
fast on unsupported layers or attention implementations (rather than deep inside
generation).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
PreTrainedModel
|
The base language model to be steered. |
required |
tokenizer
|
PreTrainedTokenizerBase | None
|
Tokenizer for substring identification. If None, attempts to retrieve from model attributes. |
None
|
session
|
The |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
PreTrainedModel |
PreTrainedModel
|
The input model (unchanged). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a configured attention module path is missing on the model, if the
model's attention implementation is not one of |
Source code in steerability/algorithms/state_control/pasta/control.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 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 | |
steer_access()
ModelAccess.MODULE; the attention module paths resolve on the live model, which
is retained for the hook closures (the generate phase is in-process).
Source code in steerability/algorithms/state_control/pasta/control.py
131 132 133 134 | |
steer_fits()
The fit artifacts the steer step produces, for the steer plan.
A HeadProfile head map produces one ("HeadProfile", "direction") fit (the lift grid,
classed as a translation-robust direction). A dict or list head map produces no fit. This
is a pure function of the args, so check() can read it before steer().
Source code in steerability/algorithms/state_control/pasta/control.py
381 382 383 384 385 386 387 388 389 390 | |
profiling
Rollout-scored attention-head profiling for PASTA, resolved at steer time.
HeadProfile is a third accepted form of PASTAArgs.head_config, beside the dict and list
forms. It is a declarative recipe that PASTA.steer() resolves through the pipeline's session:
each candidate (layer, head) is steered on its own on a task-agnostic set of profiling
prompts, scored by a SampleScorer, and ranked by the paired lift of its score over an
unsteered baseline. The selected heads become the control's dict-form head map, and the
resolution HeadProfileResult records the per-head lift, standard error, and selection so the
run can be inspected and rebuilt.
The recipe follows the toolkit's source idiom (ContrastiveFit, ConditionPointSearch):
it declares access and artifact_class for the steer plan, memoizes its resolution per model,
and its resolved head map freezes into a .spipe as a same-class state_control/pasta entry
with the fit digest on the lift grid.
Reference:
- "Tell Your Model Where to Attend: Post-hoc Attention Steering for LLMs"
Qingru Zhang, Chandan Singh, Liyuan Liu, Xiaodong Liu, Bin Yu, Jianfeng Gao, Tuo Zhao
[https://arxiv.org/abs/2311.02262](https://arxiv.org/abs/2311.02262)
logger = logging.getLogger(__name__)
module-attribute
HeadProfile
dataclass
Rollout-scored head profiling, resolved at PASTA.steer().
A recipe passed as PASTA(head_config=HeadProfile(...)). It scores each candidate
(layer, head) by steering that head alone at the profiling strength alpha and measuring
the mean gain in scorer over an unsteered baseline on rows, ranks the candidates
deterministically, filters to those that beat the baseline, and returns the top num_heads
as a dict head map. Resolution runs through the session the pipeline hands to steer(), so
the rollouts execute on the steering backend.
The paired lift and its standard error are the statistic; ranking by lift and ranking by the
raw follow rate order candidates identically (the baseline is constant across candidates),
but the pairing gives a standard error the raw rate does not. A two-stage screen bounds cost:
stage 1 scores every candidate on a fixed subset of screen_rows rows, and stage 2 rescores
only the top screen_keep candidates on every row.
The profile uses the control's scale_position; it is not a recipe field, since a profile is
only meaningful for the mechanism it is deployed with.
Attributes:
| Name | Type | Description |
|---|---|---|
rows |
Sequence[Mapping]
|
One mapping per profiling prompt. |
scorer |
SampleScorer
|
|
alpha |
float
|
The profiling strength. Required, with no default. The toolkit parameterizes
|
num_heads |
int
|
Number of heads to select. |
layers |
Sequence[int] | None
|
Candidate layers. None means every attention layer of the resolved layout; non-attention layers of a hybrid stack are never candidates. |
selection |
Literal['pooled', 'intersection']
|
|
min_lift |
float
|
A candidate is eligible when its pooled lift exceeds this value. The default
|
screen_rows |
int | None
|
Rows scored in stage 1 of the two-stage screen. Set together with
|
screen_keep |
int | None
|
Candidates rescored on every row in stage 2. At least |
gen_kwargs |
dict
|
Profiling generation parameters, normalized through
|
batch_size |
int
|
Number of rows generated per session call. Rows in a batch share one hook entry and generate in one batched pass, so larger values trade memory for wall-clock; excluded from the fit digest. |
seed |
int
|
Fixes the stage-1 subsample. |
progress_callback |
Callable[[dict], None] | None
|
Optional callback invoked once per scored candidate with a small dict
( |
Reference:
- "Tell Your Model Where to Attend: Post-hoc Attention Steering for LLMs"
Qingru Zhang, Chandan Singh, Liyuan Liu, Xiaodong Liu, Bin Yu, Jianfeng Gao, Tuo Zhao
[https://arxiv.org/abs/2311.02262](https://arxiv.org/abs/2311.02262)
Source code in steerability/algorithms/state_control/pasta/profiling.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | |
access = ModelAccess.MODULE
class-attribute
alpha
instance-attribute
artifact_class = 'direction'
class-attribute
batch_size = 8
class-attribute
instance-attribute
gen_kwargs = field(default_factory=lambda: {'max_new_tokens': 128, 'do_sample': False})
class-attribute
instance-attribute
layers = None
class-attribute
instance-attribute
min_lift = 0.0
class-attribute
instance-attribute
num_heads = 48
class-attribute
instance-attribute
progress_callback = None
class-attribute
instance-attribute
rows
instance-attribute
scorer
instance-attribute
screen_keep = None
class-attribute
instance-attribute
screen_rows = None
class-attribute
instance-attribute
seed = 0
class-attribute
instance-attribute
selection = 'pooled'
class-attribute
instance-attribute
budget(num_layers, num_heads)
Rollout counts for a (num_layers, num_heads) grid, without loading a model.
A rollout is one prompt generated once. The candidate count is restricted to layers
when set. With a screen, stage 1 scores every candidate on screen_rows rows and stage 2
rescores screen_keep candidates on every row; without one, every candidate is scored on
every row in stage 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_layers
|
int
|
Number of attention layers in the model. |
required |
num_heads
|
int
|
Number of attention heads per layer. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
A mapping with keys |
Source code in steerability/algorithms/state_control/pasta/profiling.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
fit_ingredients()
The fit-relevant recipe inputs, digested for staleness detection.
Covers rows, scorer, alpha, num_heads, layers, selection, min_lift,
screen_rows, screen_keep, gen_kwargs, and seed. batch_size and
progress_callback are execution details and are excluded; the control's own alpha is
an application parameter and is excluded here (it lives on the control, not the recipe).
The scorer digests as its qualified name, so renaming the scorer invalidates the frozen
profile.
Source code in steerability/algorithms/state_control/pasta/profiling.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
resolve(control, model, tokenizer, *, session)
Resolve the profile against model, fitting once and memoizing.
Reruns the profiling loop through session and returns the ranked, filtered
HeadProfileResult. The result is memoized per model (a weakref slot) and the control's
scale_position, so a second control sharing this recipe on the same model reuses it and
a different model refits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control
|
'PASTA'
|
The steering PASTA, consulted for |
required |
model
|
The live model to profile against. |
required | |
tokenizer
|
The tokenizer for prompt preparation and decoding. |
required | |
session
|
'SteeringSession'
|
The |
required |
Returns:
| Type | Description |
|---|---|
'HeadProfileResult'
|
The |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no candidate beats the baseline (the message names the fixes). |
Source code in steerability/algorithms/state_control/pasta/profiling.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
HeadProfileResult
dataclass
The resolution of a HeadProfile: the selected head map plus per-candidate statistics.
lift, se, n, and stage are [num_layers, max_heads] tensors with NaN (0 for n
and stage) at positions that were not candidates. stage is 1 for a candidate scored only
on the screen subset and 2 for a candidate scored on every row. group_lift is
[num_groups, num_layers, max_heads] and group_rows the per-group row counts, both None
when the rows carry no "group".
Attributes:
| Name | Type | Description |
|---|---|---|
head_config |
dict[int, list[int]]
|
The selected head map, layer index to sorted head indices. |
selected |
list[tuple[int, int]]
|
The selected candidates, in selection order. |
lift |
Tensor
|
Per-candidate mean gain over the baseline. |
se |
Tensor
|
Per-candidate standard error of the paired differences. |
n |
Tensor
|
Per-candidate number of rows scored. |
stage |
Tensor
|
Per-candidate screen stage (1 or 2), 0 for non-candidates. |
group_lift |
Tensor | None
|
Per-group lift, or None. |
groups |
list[str] | None
|
The group names, or None. |
group_rows |
list[int] | None
|
The per-group row counts, or None. |
baseline |
float
|
The unsteered mean score over all rows. |
num_rows |
int
|
The number of profiling rows. |
tie_at_cutoff |
int
|
Candidates whose lift equals the last selected candidate's. |
alpha |
float
|
The profiling strength. |
scale_position |
str
|
The control's scale position the profile was scored under. |
Source code in steerability/algorithms/state_control/pasta/profiling.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 | |
alpha
instance-attribute
baseline
instance-attribute
group_lift
instance-attribute
group_rows
instance-attribute
groups
instance-attribute
head_config
instance-attribute
lift
instance-attribute
n
instance-attribute
num_rows
instance-attribute
scale_position
instance-attribute
se
instance-attribute
selected
instance-attribute
stage
instance-attribute
tie_at_cutoff
instance-attribute
load(path)
classmethod
Read a result written by save, reproducing every field exactly.
Source code in steerability/algorithms/state_control/pasta/profiling.py
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 | |
save(path)
Write the complete result to one JSON file (tensors as nested lists, NaN as null).
Source code in steerability/algorithms/state_control/pasta/profiling.py
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 | |
to_frame()
One row per candidate, columns layer, head, lift, se, n, stage,
selected, rank, plus one lift_<group> column per group when groups are present.
Source code in steerability/algorithms/state_control/pasta/profiling.py
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 | |