wisent 0.1.1__py3-none-any.whl → 0.5.2__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 -8
- wisent/benchmarks/__init__.py +0 -0
- wisent/benchmarks/coding/__init__.py +0 -0
- wisent/benchmarks/coding/metrics/__init__.py +0 -0
- wisent/benchmarks/coding/metrics/core/__init__.py +0 -0
- wisent/benchmarks/coding/metrics/core/atoms.py +36 -0
- wisent/benchmarks/coding/metrics/evaluator.py +275 -0
- wisent/benchmarks/coding/metrics/passk.py +66 -0
- wisent/benchmarks/coding/output_sanitizer/__init__.py +0 -0
- wisent/benchmarks/coding/output_sanitizer/core/__init__.py +0 -0
- wisent/benchmarks/coding/output_sanitizer/core/atoms.py +27 -0
- wisent/benchmarks/coding/output_sanitizer/cpp_sanitizer.py +62 -0
- wisent/benchmarks/coding/output_sanitizer/java_sanitizer.py +78 -0
- wisent/benchmarks/coding/output_sanitizer/python_sanitizer.py +94 -0
- wisent/benchmarks/coding/output_sanitizer/utils.py +107 -0
- wisent/benchmarks/coding/providers/__init__.py +18 -0
- wisent/benchmarks/coding/providers/core/__init__.py +0 -0
- wisent/benchmarks/coding/providers/core/atoms.py +31 -0
- wisent/benchmarks/coding/providers/livecodebench/__init__.py +0 -0
- wisent/benchmarks/coding/providers/livecodebench/provider.py +53 -0
- wisent/benchmarks/coding/safe_docker/__init__.py +0 -0
- wisent/benchmarks/coding/safe_docker/core/__init__.py +0 -0
- wisent/benchmarks/coding/safe_docker/core/atoms.py +105 -0
- wisent/benchmarks/coding/safe_docker/core/runtime.py +118 -0
- wisent/benchmarks/coding/safe_docker/entrypoint.py +123 -0
- wisent/benchmarks/coding/safe_docker/recipes.py +60 -0
- wisent/classifiers/__init__.py +0 -0
- wisent/classifiers/core/__init__.py +0 -0
- wisent/classifiers/core/atoms.py +747 -0
- wisent/classifiers/models/__init__.py +0 -0
- wisent/classifiers/models/logistic.py +29 -0
- wisent/classifiers/models/mlp.py +47 -0
- wisent/cli/__init__.py +0 -0
- wisent/cli/classifiers/__init__.py +0 -0
- wisent/cli/classifiers/classifier_rotator.py +137 -0
- wisent/cli/cli_logger.py +142 -0
- wisent/cli/data_loaders/__init__.py +0 -0
- wisent/cli/data_loaders/data_loader_rotator.py +96 -0
- wisent/cli/evaluators/__init__.py +0 -0
- wisent/cli/evaluators/evaluator_rotator.py +148 -0
- wisent/cli/steering_methods/__init__.py +0 -0
- wisent/cli/steering_methods/steering_rotator.py +110 -0
- wisent/cli/wisent_cli/__init__.py +0 -0
- wisent/cli/wisent_cli/commands/__init__.py +0 -0
- wisent/cli/wisent_cli/commands/help_cmd.py +52 -0
- wisent/cli/wisent_cli/commands/listing.py +154 -0
- wisent/cli/wisent_cli/commands/train_cmd.py +322 -0
- wisent/cli/wisent_cli/main.py +93 -0
- wisent/cli/wisent_cli/shell.py +80 -0
- wisent/cli/wisent_cli/ui.py +69 -0
- wisent/cli/wisent_cli/util/__init__.py +0 -0
- wisent/cli/wisent_cli/util/aggregations.py +43 -0
- wisent/cli/wisent_cli/util/parsing.py +126 -0
- wisent/cli/wisent_cli/version.py +4 -0
- wisent/core/__init__.py +27 -0
- wisent/core/activations/__init__.py +0 -0
- wisent/core/activations/activations_collector.py +338 -0
- wisent/core/activations/core/__init__.py +0 -0
- wisent/core/activations/core/atoms.py +216 -0
- wisent/core/agent/__init__.py +18 -0
- wisent/core/agent/budget.py +638 -0
- wisent/core/agent/device_benchmarks.py +685 -0
- wisent/core/agent/diagnose/__init__.py +55 -0
- wisent/core/agent/diagnose/agent_classifier_decision.py +641 -0
- wisent/core/agent/diagnose/classifier_marketplace.py +554 -0
- wisent/core/agent/diagnose/create_classifier.py +1154 -0
- wisent/core/agent/diagnose/response_diagnostics.py +268 -0
- wisent/core/agent/diagnose/select_classifiers.py +506 -0
- wisent/core/agent/diagnose/synthetic_classifier_option.py +754 -0
- wisent/core/agent/diagnose/tasks/__init__.py +33 -0
- wisent/core/agent/diagnose/tasks/task_manager.py +1456 -0
- wisent/core/agent/diagnose/tasks/task_relevance.py +94 -0
- wisent/core/agent/diagnose/tasks/task_selector.py +151 -0
- wisent/core/agent/diagnose/test_synthetic_classifier.py +71 -0
- wisent/core/agent/diagnose.py +242 -0
- wisent/core/agent/steer.py +212 -0
- wisent/core/agent/timeout.py +134 -0
- wisent/core/autonomous_agent.py +1234 -0
- wisent/core/bigcode_integration.py +583 -0
- wisent/core/contrastive_pairs/__init__.py +15 -0
- wisent/core/contrastive_pairs/core/__init__.py +0 -0
- wisent/core/contrastive_pairs/core/atoms.py +45 -0
- wisent/core/contrastive_pairs/core/buliders.py +59 -0
- wisent/core/contrastive_pairs/core/pair.py +178 -0
- wisent/core/contrastive_pairs/core/response.py +152 -0
- wisent/core/contrastive_pairs/core/serialization.py +300 -0
- wisent/core/contrastive_pairs/core/set.py +133 -0
- wisent/core/contrastive_pairs/diagnostics/__init__.py +45 -0
- wisent/core/contrastive_pairs/diagnostics/activations.py +53 -0
- wisent/core/contrastive_pairs/diagnostics/base.py +73 -0
- wisent/core/contrastive_pairs/diagnostics/control_vectors.py +169 -0
- wisent/core/contrastive_pairs/diagnostics/coverage.py +79 -0
- wisent/core/contrastive_pairs/diagnostics/divergence.py +98 -0
- wisent/core/contrastive_pairs/diagnostics/duplicates.py +116 -0
- wisent/core/contrastive_pairs/lm_eval_pairs/__init__.py +0 -0
- wisent/core/contrastive_pairs/lm_eval_pairs/atoms.py +238 -0
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_extractor_manifest.py +8 -0
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_extractor_registry.py +132 -0
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/__init__.py +0 -0
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/winogrande.py +115 -0
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_pairs_generation.py +50 -0
- wisent/core/data_loaders/__init__.py +0 -0
- wisent/core/data_loaders/core/__init__.py +0 -0
- wisent/core/data_loaders/core/atoms.py +98 -0
- wisent/core/data_loaders/loaders/__init__.py +0 -0
- wisent/core/data_loaders/loaders/custom.py +120 -0
- wisent/core/data_loaders/loaders/lm_loader.py +218 -0
- wisent/core/detection_handling.py +257 -0
- wisent/core/download_full_benchmarks.py +1386 -0
- wisent/core/evaluators/__init__.py +0 -0
- wisent/core/evaluators/oracles/__init__.py +0 -0
- wisent/core/evaluators/oracles/interactive.py +73 -0
- wisent/core/evaluators/oracles/nlp_evaluator.py +440 -0
- wisent/core/evaluators/oracles/user_specified.py +67 -0
- wisent/core/hyperparameter_optimizer.py +429 -0
- wisent/core/lm_eval_harness_ground_truth.py +1396 -0
- wisent/core/log_likelihoods_evaluator.py +321 -0
- wisent/core/managed_cached_benchmarks.py +595 -0
- wisent/core/mixed_benchmark_sampler.py +364 -0
- wisent/core/model_config_manager.py +330 -0
- wisent/core/model_persistence.py +317 -0
- wisent/core/models/__init__.py +0 -0
- wisent/core/models/core/__init__.py +0 -0
- wisent/core/models/core/atoms.py +460 -0
- wisent/core/models/wisent_model.py +727 -0
- wisent/core/multi_steering.py +316 -0
- wisent/core/optuna/__init__.py +57 -0
- wisent/core/optuna/classifier/__init__.py +25 -0
- wisent/core/optuna/classifier/activation_generator.py +349 -0
- wisent/core/optuna/classifier/classifier_cache.py +509 -0
- wisent/core/optuna/classifier/optuna_classifier_optimizer.py +606 -0
- wisent/core/optuna/steering/__init__.py +0 -0
- wisent/core/optuna/steering/bigcode_evaluator_wrapper.py +188 -0
- wisent/core/optuna/steering/data_utils.py +342 -0
- wisent/core/optuna/steering/metrics.py +474 -0
- wisent/core/optuna/steering/optuna_pipeline.py +1738 -0
- wisent/core/optuna/steering/steering_optimization.py +1111 -0
- wisent/core/parser.py +1668 -0
- wisent/core/prompts/__init__.py +0 -0
- wisent/core/prompts/core/__init__.py +0 -0
- wisent/core/prompts/core/atom.py +57 -0
- wisent/core/prompts/core/prompt_formater.py +157 -0
- wisent/core/prompts/prompt_stratiegies/__init__.py +0 -0
- wisent/core/prompts/prompt_stratiegies/direct_completion.py +24 -0
- wisent/core/prompts/prompt_stratiegies/instruction_following.py +24 -0
- wisent/core/prompts/prompt_stratiegies/multiple_choice.py +29 -0
- wisent/core/prompts/prompt_stratiegies/role_playing.py +31 -0
- wisent/core/representation.py +5 -0
- wisent/core/sample_size_optimizer.py +648 -0
- wisent/core/sample_size_optimizer_v2.py +355 -0
- wisent/core/save_results.py +277 -0
- wisent/core/steering.py +652 -0
- wisent/core/steering_method.py +26 -0
- wisent/core/steering_methods/__init__.py +0 -0
- wisent/core/steering_methods/core/__init__.py +0 -0
- wisent/core/steering_methods/core/atoms.py +153 -0
- wisent/core/steering_methods/methods/__init__.py +0 -0
- wisent/core/steering_methods/methods/caa.py +44 -0
- wisent/core/steering_optimizer.py +1297 -0
- wisent/core/task_interface.py +132 -0
- wisent/core/task_selector.py +189 -0
- wisent/core/tasks/__init__.py +175 -0
- wisent/core/tasks/aime_task.py +141 -0
- wisent/core/tasks/file_task.py +211 -0
- wisent/core/tasks/hle_task.py +180 -0
- wisent/core/tasks/hmmt_task.py +119 -0
- wisent/core/tasks/livecodebench_task.py +201 -0
- wisent/core/tasks/livemathbench_task.py +158 -0
- wisent/core/tasks/lm_eval_task.py +455 -0
- wisent/core/tasks/math500_task.py +84 -0
- wisent/core/tasks/polymath_task.py +146 -0
- wisent/core/tasks/supergpqa_task.py +220 -0
- wisent/core/time_estimator.py +149 -0
- wisent/core/timing_calibration.py +174 -0
- wisent/core/tracking/__init__.py +54 -0
- wisent/core/tracking/latency.py +618 -0
- wisent/core/tracking/memory.py +359 -0
- wisent/core/trainers/__init__.py +0 -0
- wisent/core/trainers/core/__init__.py +11 -0
- wisent/core/trainers/core/atoms.py +45 -0
- wisent/core/trainers/steering_trainer.py +271 -0
- wisent/core/user_model_config.py +158 -0
- wisent/opti/__init__.py +0 -0
- wisent/opti/core/__init__.py +0 -0
- wisent/opti/core/atoms.py +175 -0
- wisent/opti/methods/__init__.py +0 -0
- wisent/opti/methods/opti_classificator.py +172 -0
- wisent/opti/methods/opti_steering.py +138 -0
- wisent/synthetic/__init__.py +0 -0
- wisent/synthetic/cleaners/__init__.py +0 -0
- wisent/synthetic/cleaners/core/__init__.py +0 -0
- wisent/synthetic/cleaners/core/atoms.py +58 -0
- wisent/synthetic/cleaners/deduper_cleaner.py +53 -0
- wisent/synthetic/cleaners/methods/__init__.py +0 -0
- wisent/synthetic/cleaners/methods/base_dedupers.py +320 -0
- wisent/synthetic/cleaners/methods/base_refusalers.py +286 -0
- wisent/synthetic/cleaners/methods/core/__init__.py +0 -0
- wisent/synthetic/cleaners/methods/core/atoms.py +47 -0
- wisent/synthetic/cleaners/pairs_cleaner.py +90 -0
- wisent/synthetic/cleaners/refusaler_cleaner.py +133 -0
- wisent/synthetic/db_instructions/__init__.py +0 -0
- wisent/synthetic/db_instructions/core/__init__.py +0 -0
- wisent/synthetic/db_instructions/core/atoms.py +25 -0
- wisent/synthetic/db_instructions/mini_dp.py +37 -0
- wisent/synthetic/generators/__init__.py +0 -0
- wisent/synthetic/generators/core/__init__.py +0 -0
- wisent/synthetic/generators/core/atoms.py +73 -0
- wisent/synthetic/generators/diversities/__init__.py +0 -0
- wisent/synthetic/generators/diversities/core/__init__.py +0 -0
- wisent/synthetic/generators/diversities/core/core.py +68 -0
- wisent/synthetic/generators/diversities/methods/__init__.py +0 -0
- wisent/synthetic/generators/diversities/methods/fast_diversity.py +249 -0
- wisent/synthetic/generators/pairs_generator.py +179 -0
- wisent-0.5.2.dist-info/METADATA +67 -0
- wisent-0.5.2.dist-info/RECORD +218 -0
- {wisent-0.1.1.dist-info → wisent-0.5.2.dist-info}/WHEEL +1 -1
- {wisent-0.1.1.dist-info → wisent-0.5.2.dist-info/licenses}/LICENSE +2 -2
- wisent/activations/__init__.py +0 -9
- wisent/activations/client.py +0 -97
- wisent/activations/extractor.py +0 -251
- wisent/activations/models.py +0 -95
- wisent/client.py +0 -45
- wisent/control_vector/__init__.py +0 -9
- wisent/control_vector/client.py +0 -85
- wisent/control_vector/manager.py +0 -168
- wisent/control_vector/models.py +0 -70
- wisent/inference/__init__.py +0 -9
- wisent/inference/client.py +0 -103
- wisent/inference/inferencer.py +0 -250
- wisent/inference/models.py +0 -66
- wisent/utils/__init__.py +0 -3
- wisent/utils/auth.py +0 -30
- wisent/utils/http.py +0 -228
- wisent/version.py +0 -3
- wisent-0.1.1.dist-info/METADATA +0 -142
- wisent-0.1.1.dist-info/RECORD +0 -23
- {wisent-0.1.1.dist-info → wisent-0.5.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
import typer
|
|
5
|
+
|
|
6
|
+
from wisent.cli.wisent_cli.version import APP_NAME, APP_VERSION
|
|
7
|
+
from wisent.cli.wisent_cli.ui import print_banner
|
|
8
|
+
from wisent.cli.wisent_cli.commands.listing import app as listing_app
|
|
9
|
+
from wisent.cli.wisent_cli.commands.train_cmd import app as train_app
|
|
10
|
+
from wisent.cli.wisent_cli.commands.help_cmd import app as help_router_app
|
|
11
|
+
from wisent.cli.wisent_cli.shell import app as shell_app
|
|
12
|
+
|
|
13
|
+
app = typer.Typer(
|
|
14
|
+
no_args_is_help=True,
|
|
15
|
+
add_completion=False,
|
|
16
|
+
rich_markup_mode="markdown",
|
|
17
|
+
help=(
|
|
18
|
+
"[bold]Wisent Guard[/] – steerable activations / steering vectors.\n"
|
|
19
|
+
"Collect activations, train steering vectors, and inspect loaders & methods.\n\n"
|
|
20
|
+
"Natural commands (no dashes) + `help <topic>` and a `wisent` shell."
|
|
21
|
+
),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
app.add_typer(listing_app, name="list")
|
|
25
|
+
app.add_typer(train_app, name="") # attach commands directly (e.g., train)
|
|
26
|
+
app.add_typer(help_router_app, name="") # help router lives at root (help ...)
|
|
27
|
+
app.add_typer(shell_app, name="shell")
|
|
28
|
+
|
|
29
|
+
STATE = {"verbose": False}
|
|
30
|
+
|
|
31
|
+
@app.callback(invoke_without_command=True)
|
|
32
|
+
def _main_callback(
|
|
33
|
+
ctx: typer.Context,
|
|
34
|
+
version: Optional[bool] = typer.Option(None, "--version", "-V", help="Show version and exit."),
|
|
35
|
+
no_banner: bool = typer.Option(False, "--no-banner", help="Disable the startup banner."),
|
|
36
|
+
verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose logging."),
|
|
37
|
+
logo_width: Optional[int] = typer.Option(None, "--logo-width", help="Width of the wisent badge (28–96)."),
|
|
38
|
+
):
|
|
39
|
+
"""
|
|
40
|
+
Welcome to **Wisent Guard**.
|
|
41
|
+
|
|
42
|
+
Examples:
|
|
43
|
+
• `wisent help train`
|
|
44
|
+
• `wisent train model meta-llama/Llama-3.2-1B-Instruct loader custom path ./custom.json training_limit 5 method caa`
|
|
45
|
+
• `wisent list list-methods` (methods)
|
|
46
|
+
• `wisent list list-loaders` (loaders)
|
|
47
|
+
• `wisent list list-aggregations` (aggregations)
|
|
48
|
+
• `wisent shell start` (interactive 'wisent' prompt)
|
|
49
|
+
"""
|
|
50
|
+
if version:
|
|
51
|
+
typer.echo(f"{APP_NAME} {APP_VERSION}")
|
|
52
|
+
raise typer.Exit()
|
|
53
|
+
|
|
54
|
+
STATE["verbose"] = verbose
|
|
55
|
+
if not no_banner and (ctx.invoked_subcommand is None or ctx.info_name in {"--help", None}):
|
|
56
|
+
print_banner(APP_NAME, width=logo_width or 48)
|
|
57
|
+
|
|
58
|
+
if ctx.invoked_subcommand is None:
|
|
59
|
+
typer.echo(ctx.get_help())
|
|
60
|
+
raise typer.Exit()
|
|
61
|
+
|
|
62
|
+
@app.command("instructions")
|
|
63
|
+
def instructions():
|
|
64
|
+
msg = """
|
|
65
|
+
[bold]Quickstart (no-dash style)[/]
|
|
66
|
+
|
|
67
|
+
• Preview a run without executing:
|
|
68
|
+
[b]wisent train model gpt2 plan-only true[/]
|
|
69
|
+
|
|
70
|
+
• Discover components:
|
|
71
|
+
[b]wisent list list-methods[/] | [b]wisent list list-loaders[/] | [b]wisent list list-aggregations[/]
|
|
72
|
+
|
|
73
|
+
• Get help:
|
|
74
|
+
[b]wisent help train[/], [b]wisent help method caa[/], [b]wisent help loader custom[/]
|
|
75
|
+
|
|
76
|
+
• Full training example (natural):
|
|
77
|
+
[b]wisent train model meta-llama/Llama-3.2-1B-Instruct loader custom path ./wisent_guard/cli/cli_examples/custom_dataset.json training_limit 5 \\
|
|
78
|
+
method caa layers 10..12 aggregation continuation_token device cuda dtype float16 save_dir ./steering_output normalize_layers true[/]
|
|
79
|
+
|
|
80
|
+
Tip: add [b]interactive true[/] for a guided wizard.
|
|
81
|
+
"""
|
|
82
|
+
try:
|
|
83
|
+
from rich.panel import Panel
|
|
84
|
+
from wisent.cli.wisent_cli.ui import echo
|
|
85
|
+
echo(Panel.fit(msg, title="Instructions", border_style="green"))
|
|
86
|
+
except Exception:
|
|
87
|
+
print(msg)
|
|
88
|
+
|
|
89
|
+
def run():
|
|
90
|
+
app()
|
|
91
|
+
|
|
92
|
+
if __name__ == "__main__":
|
|
93
|
+
run()
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import shlex
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
from wisent.cli.wisent_cli.ui import print_banner, echo
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
from rich.panel import Panel
|
|
9
|
+
HAS_RICH = True
|
|
10
|
+
except Exception:
|
|
11
|
+
HAS_RICH = False
|
|
12
|
+
|
|
13
|
+
__all__ = ["app", "start"]
|
|
14
|
+
|
|
15
|
+
app = typer.Typer(help="Interactive shell")
|
|
16
|
+
|
|
17
|
+
def _run_cli_line(line: str) -> None:
|
|
18
|
+
from typer.main import get_command
|
|
19
|
+
from wisent.cli.wisent_cli.main import app as root_app
|
|
20
|
+
click_cmd = get_command(root_app)
|
|
21
|
+
args = shlex.split(line)
|
|
22
|
+
try:
|
|
23
|
+
click_cmd.main(args=args, standalone_mode=False, prog_name="wisent")
|
|
24
|
+
except SystemExit as e:
|
|
25
|
+
if e.code not in (0, None):
|
|
26
|
+
raise
|
|
27
|
+
|
|
28
|
+
@app.command("start")
|
|
29
|
+
def start(
|
|
30
|
+
logo_width: int = typer.Option(48, "--logo-width", "-w", help="Logo width for the banner (28–96)."),
|
|
31
|
+
show_banner: bool = typer.Option(True, "--banner/--no-banner", help="Show banner when the shell starts."),
|
|
32
|
+
):
|
|
33
|
+
"""
|
|
34
|
+
Launch the interactive **wisent** shell.
|
|
35
|
+
|
|
36
|
+
Inside the shell, run:
|
|
37
|
+
• `help` / `help train` / `help method caa`
|
|
38
|
+
• `instructions`
|
|
39
|
+
• `train model ...` (no dashes)
|
|
40
|
+
|
|
41
|
+
Type `exit`, `quit`, or press `Ctrl-D` to leave.
|
|
42
|
+
"""
|
|
43
|
+
if show_banner:
|
|
44
|
+
print_banner("Wisent Guard", logo_width)
|
|
45
|
+
|
|
46
|
+
hint = "Type 'help', 'help train', 'instructions', or any command like 'train model ...'. Type 'exit' to quit."
|
|
47
|
+
if HAS_RICH:
|
|
48
|
+
echo(Panel(hint, title="Welcome to the wisent shell", border_style="green"))
|
|
49
|
+
else:
|
|
50
|
+
print(hint)
|
|
51
|
+
|
|
52
|
+
GREEN, OFF = ("\x1b[32m", "\x1b[0m")
|
|
53
|
+
while True:
|
|
54
|
+
try:
|
|
55
|
+
if HAS_RICH:
|
|
56
|
+
from rich.console import Console
|
|
57
|
+
line = Console().input("[bold green]wisent[/] ")
|
|
58
|
+
else:
|
|
59
|
+
line = input(f"{GREEN}wisent{OFF} ")
|
|
60
|
+
except (EOFError, KeyboardInterrupt):
|
|
61
|
+
typer.echo("\nBye.")
|
|
62
|
+
break
|
|
63
|
+
|
|
64
|
+
line = line.strip()
|
|
65
|
+
if not line:
|
|
66
|
+
continue
|
|
67
|
+
if line in {"exit", "quit", "q"}:
|
|
68
|
+
typer.echo("Bye.")
|
|
69
|
+
break
|
|
70
|
+
if line in {"help", "--help", "-h"}:
|
|
71
|
+
_run_cli_line("--help")
|
|
72
|
+
continue
|
|
73
|
+
if line.startswith("help "):
|
|
74
|
+
_run_cli_line(line)
|
|
75
|
+
continue
|
|
76
|
+
if line in {"instructions", "--instructions"}:
|
|
77
|
+
_run_cli_line("instructions")
|
|
78
|
+
continue
|
|
79
|
+
|
|
80
|
+
_run_cli_line(line)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
from rich.panel import Panel
|
|
8
|
+
from rich.text import Text
|
|
9
|
+
HAS_RICH = True
|
|
10
|
+
_console = Console()
|
|
11
|
+
except Exception: # pragma: no cover
|
|
12
|
+
HAS_RICH = False
|
|
13
|
+
_console = None
|
|
14
|
+
|
|
15
|
+
__all__ = ["print_banner", "echo"]
|
|
16
|
+
|
|
17
|
+
def _render_wisent_mark(width: int = 48) -> str:
|
|
18
|
+
logo = """
|
|
19
|
+
................. .:--++*##%%%%##**+=-:. .................
|
|
20
|
+
.. .:=*%@@@@@@@%%%%%%%@@@@@@%*=:. ..
|
|
21
|
+
. .-*%@@@%#+=-::.........:-=+#%@@@%*=. .
|
|
22
|
+
. -*%@@@#=:. .:=*%@@@*-. .
|
|
23
|
+
. .-#@@@*=. .-*@@@#-. .
|
|
24
|
+
. :#@@@*: :+%@@#- .
|
|
25
|
+
. .+@@@*: :+@@@+. .
|
|
26
|
+
. .*@@@@%*=:. -%@@#: .
|
|
27
|
+
. .#@@#=*%@@@%*-:. .#@@%: .
|
|
28
|
+
..*@@%. .-+#@@@@#+-:. .*@@%..
|
|
29
|
+
.=@@@- :-+#@@@@%*=:. .%@@*.
|
|
30
|
+
:#@@+ .:-+#@@@@%#+=:. -@@@-
|
|
31
|
+
=@@@: .-=*%@@@@%#+=:.. .#@@+
|
|
32
|
+
+@@@*=:. .:-+*%@@@@%#*=-:.. *@@+
|
|
33
|
+
+@@@@@@#+-.. .:-=*#@@@@@%#*+--.. +@@+
|
|
34
|
+
+@@#-+%@@@%: .:-=*#%@@@@@%#*+=-:.*@@+
|
|
35
|
+
=@@%. .=@@@: ..:-=+#%%@@@@@%@@@+
|
|
36
|
+
:%@@= :@@@- ..::-=+#@@@=
|
|
37
|
+
.+@@%. .#@@* +@@#:
|
|
38
|
+
..%@@*. =@@@: =@@@-.
|
|
39
|
+
. :%@@*..#@@#. .:.. =@@@= .
|
|
40
|
+
. :%@@*.:%@@*. :#@@%#*+=-::..+@@@= .
|
|
41
|
+
. :#@@%-:%@@#: .+@@@#%%@@@@@@%%@@%- .
|
|
42
|
+
. .+@@@*=#@@%- .=%@@%=...::-=#@@@@*. .
|
|
43
|
+
. :*@@@#%@@@*: .=%@@@+. .:*%@@#- .
|
|
44
|
+
. :+%@@@@@@@*-. :=*@@@%+. .-+%@@@*-. .
|
|
45
|
+
. .=*%@@@@@@#+:.:-+#@@@%*-. .:-+#%@@@#+: .
|
|
46
|
+
. .-+#%@@@@@@@@@@@@#*+**#@@@@@%*=:. .
|
|
47
|
+
.............. ..-=+*#%%%@@@@@@@@%%#*=-:. ..............
|
|
48
|
+
................... ....:::::::::.... ...................
|
|
49
|
+
""".strip("\n")
|
|
50
|
+
return "\n".join(line.center(width) for line in logo.splitlines())
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def print_banner(title: str, width: int | None = None) -> None:
|
|
54
|
+
if HAS_RICH:
|
|
55
|
+
usable = 64 if width is None else width
|
|
56
|
+
badge = _render_wisent_mark(usable)
|
|
57
|
+
_console.print(Panel.fit(Text(badge, style="green"), title=f"[b green]{title}[/]", border_style="green"))
|
|
58
|
+
_console.print("[dim]Steering vectors & activation tooling[/]\n")
|
|
59
|
+
else:
|
|
60
|
+
GREEN, OFF = "\x1b[32m", "\x1b[0m"
|
|
61
|
+
print(GREEN + _render_wisent_mark(width or 48) + OFF)
|
|
62
|
+
print(f"{title} – Steering vectors & activation tooling\n")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def echo(obj: Any) -> None:
|
|
66
|
+
if HAS_RICH:
|
|
67
|
+
_console.print(obj)
|
|
68
|
+
else:
|
|
69
|
+
print(obj)
|
|
File without changes
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from typing import Dict, Optional
|
|
3
|
+
|
|
4
|
+
__all__ = ["agg_cls", "descriptions", "name_map", "pick"]
|
|
5
|
+
|
|
6
|
+
def agg_cls():
|
|
7
|
+
from wisent.core.activations.core.atoms import ActivationAggregationStrategy
|
|
8
|
+
return ActivationAggregationStrategy
|
|
9
|
+
|
|
10
|
+
def descriptions() -> Dict[object, str]:
|
|
11
|
+
A = agg_cls()
|
|
12
|
+
return {
|
|
13
|
+
A.CHOICE_TOKEN: "Target A/B choice tokens (multiple choice).",
|
|
14
|
+
A.CONTINUATION_TOKEN: "Use the first token of the continuation.",
|
|
15
|
+
A.LAST_TOKEN: "Always select the last token.",
|
|
16
|
+
A.FIRST_TOKEN: "Always select the first token.",
|
|
17
|
+
A.MEAN_POOLING: "Aggregate by mean over all tokens.",
|
|
18
|
+
A.MAX_POOLING: "Aggregate by max over all tokens.",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
def name_map() -> Dict[str, object]:
|
|
22
|
+
A = agg_cls()
|
|
23
|
+
d = descriptions()
|
|
24
|
+
mapping = {s.name.lower(): s for s in d}
|
|
25
|
+
mapping.update({
|
|
26
|
+
"cont": A.CONTINUATION_TOKEN,
|
|
27
|
+
"choice": A.CHOICE_TOKEN,
|
|
28
|
+
"mean": A.MEAN_POOLING,
|
|
29
|
+
"max": A.MAX_POOLING,
|
|
30
|
+
"first": A.FIRST_TOKEN,
|
|
31
|
+
"last": A.LAST_TOKEN,
|
|
32
|
+
})
|
|
33
|
+
return mapping
|
|
34
|
+
|
|
35
|
+
def pick(name: Optional[str]):
|
|
36
|
+
if not name:
|
|
37
|
+
return agg_cls().CONTINUATION_TOKEN
|
|
38
|
+
key = name.strip().lower()
|
|
39
|
+
mapping = name_map()
|
|
40
|
+
if key not in mapping:
|
|
41
|
+
valid = ", ".join(sorted(mapping.keys()))
|
|
42
|
+
raise ValueError(f"Unknown aggregation {name!r}. Valid: {valid}")
|
|
43
|
+
return mapping[key]
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import re
|
|
3
|
+
from typing import Dict, List, Optional, Tuple
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"to_bool", "parse_layers", "parse_kv", "parse_natural_tokens",
|
|
7
|
+
"BOOL_TRUE", "BOOL_FALSE", "DTYPE_MAP", "TOP_KEYS"
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
BOOL_TRUE = {"1", "true", "yes", "y", "on"}
|
|
11
|
+
BOOL_FALSE = {"0", "false", "no", "n", "off"}
|
|
12
|
+
|
|
13
|
+
DTYPE_MAP = {None: None, "float32": "float32", "float16": "float16", "bfloat16": "bfloat16"}
|
|
14
|
+
|
|
15
|
+
TOP_KEYS = {
|
|
16
|
+
"model", "loader", "loaders_location", "methods_location", "method", "layers",
|
|
17
|
+
"aggregation", "device", "store_device", "dtype", "save_dir",
|
|
18
|
+
"return_full_sequence", "normalize_layers", "interactive", "plan-only", "plan_only", "confirm"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
def to_bool(s: str) -> bool:
|
|
22
|
+
ls = s.lower()
|
|
23
|
+
if ls in BOOL_TRUE: return True
|
|
24
|
+
if ls in BOOL_FALSE: return False
|
|
25
|
+
raise ValueError(f"Expected a boolean (true/false), got {s!r}")
|
|
26
|
+
|
|
27
|
+
def parse_layers(spec: Optional[str]) -> Optional[str]:
|
|
28
|
+
if not spec: return None
|
|
29
|
+
s = spec.strip().replace(" ", "")
|
|
30
|
+
if re.match(r"^\d+(,\d+)*$", s): # 5,7,9
|
|
31
|
+
return s
|
|
32
|
+
s = s.replace("-", "..").replace(":", "..")
|
|
33
|
+
if re.match(r"^\d+\.\.(\d+)$", s): return s
|
|
34
|
+
if re.match(r"^\d+$", s): return s
|
|
35
|
+
raise ValueError("Invalid layers spec. Use '12' or '5,10,20' or '10..20' (also '10-20'/'10:20').")
|
|
36
|
+
|
|
37
|
+
def parse_kv(items: List[str]) -> Dict[str, object]:
|
|
38
|
+
out: Dict[str, object] = {}
|
|
39
|
+
for item in items:
|
|
40
|
+
if "=" not in item:
|
|
41
|
+
raise ValueError(f"Expected key=value, got: {item!r}")
|
|
42
|
+
k, v = item.split("=", 1)
|
|
43
|
+
k, v = k.strip(), v.strip()
|
|
44
|
+
lv = v.lower()
|
|
45
|
+
if lv in {"true", "false"}:
|
|
46
|
+
out[k] = (lv == "true")
|
|
47
|
+
else:
|
|
48
|
+
try:
|
|
49
|
+
out[k] = float(v) if "." in v else int(v)
|
|
50
|
+
except ValueError:
|
|
51
|
+
out[k] = v
|
|
52
|
+
return out
|
|
53
|
+
|
|
54
|
+
def parse_natural_tokens(tokens: List[str]) -> Tuple[Dict[str, str], Dict[str, str], Dict[str, str]]:
|
|
55
|
+
"""
|
|
56
|
+
Return (top_level, loader_kwargs, method_kwargs).
|
|
57
|
+
Understands:
|
|
58
|
+
- key value
|
|
59
|
+
- key=value
|
|
60
|
+
- sections: loader ..., method ...
|
|
61
|
+
- dotted keys: loader.path=..., method.alpha=...
|
|
62
|
+
"""
|
|
63
|
+
top: Dict[str, str] = {}
|
|
64
|
+
lkw: Dict[str, str] = {}
|
|
65
|
+
mkw: Dict[str, str] = {}
|
|
66
|
+
ctx: Optional[str] = None
|
|
67
|
+
|
|
68
|
+
i = 0
|
|
69
|
+
while i < len(tokens):
|
|
70
|
+
tok = tokens[i]
|
|
71
|
+
|
|
72
|
+
if "=" in tok:
|
|
73
|
+
k, v = tok.split("=", 1)
|
|
74
|
+
k, v = k.strip(), v.strip()
|
|
75
|
+
if k.startswith("loader."):
|
|
76
|
+
lkw[k.split(".", 1)[1]] = v
|
|
77
|
+
elif k.startswith("method."):
|
|
78
|
+
mkw[k.split(".", 1)[1]] = v
|
|
79
|
+
elif k in TOP_KEYS:
|
|
80
|
+
top[k] = v
|
|
81
|
+
elif ctx == "loader":
|
|
82
|
+
lkw[k] = v
|
|
83
|
+
elif ctx == "method":
|
|
84
|
+
mkw[k] = v
|
|
85
|
+
else:
|
|
86
|
+
top[k] = v
|
|
87
|
+
i += 1
|
|
88
|
+
continue
|
|
89
|
+
|
|
90
|
+
lt = tok.lower()
|
|
91
|
+
if lt in {"loader", "method"}:
|
|
92
|
+
ctx = lt
|
|
93
|
+
if i + 1 < len(tokens) and "=" not in tokens[i + 1] and tokens[i + 1].lower() not in TOP_KEYS:
|
|
94
|
+
if lt == "loader":
|
|
95
|
+
top["loader"] = tokens[i + 1]
|
|
96
|
+
else:
|
|
97
|
+
top["method"] = tokens[i + 1]
|
|
98
|
+
i += 2
|
|
99
|
+
else:
|
|
100
|
+
i += 1
|
|
101
|
+
continue
|
|
102
|
+
|
|
103
|
+
if lt in TOP_KEYS:
|
|
104
|
+
if i + 1 >= len(tokens) or tokens[i + 1].lower() in TOP_KEYS or "=" in tokens[i + 1]:
|
|
105
|
+
top[lt] = "true"
|
|
106
|
+
i += 1
|
|
107
|
+
else:
|
|
108
|
+
top[lt] = tokens[i + 1]
|
|
109
|
+
i += 2
|
|
110
|
+
ctx = None
|
|
111
|
+
continue
|
|
112
|
+
|
|
113
|
+
if ctx in {"loader", "method"}:
|
|
114
|
+
if i + 1 < len(tokens) and "=" not in tokens[i + 1] and tokens[i + 1].lower() not in TOP_KEYS:
|
|
115
|
+
key = tok
|
|
116
|
+
val = tokens[i + 1]
|
|
117
|
+
(lkw if ctx == "loader" else mkw)[key] = val
|
|
118
|
+
i += 2
|
|
119
|
+
else:
|
|
120
|
+
(lkw if ctx == "loader" else mkw)[tok] = "true"
|
|
121
|
+
i += 1
|
|
122
|
+
continue
|
|
123
|
+
|
|
124
|
+
i += 1
|
|
125
|
+
|
|
126
|
+
return top, lkw, mkw
|
wisent/core/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from wisent.core.activations import Activations
|
|
2
|
+
from wisent.core.classifier.classifier import ActivationClassifier, Classifier
|
|
3
|
+
|
|
4
|
+
from .utils.device import empty_device_cache, preferred_dtype, resolve_default_device, resolve_device, resolve_torch_device
|
|
5
|
+
from .steering import SteeringMethod, SteeringType
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"ActivationClassifier",
|
|
9
|
+
"ActivationHooks",
|
|
10
|
+
"Activations",
|
|
11
|
+
"Classifier",
|
|
12
|
+
"ContrastivePairSet",
|
|
13
|
+
"Layer",
|
|
14
|
+
"Model",
|
|
15
|
+
"ModelParameterOptimizer",
|
|
16
|
+
"PromptFormat",
|
|
17
|
+
"SecureCodeEvaluator",
|
|
18
|
+
"SteeringMethod",
|
|
19
|
+
"SteeringType",
|
|
20
|
+
"TokenScore",
|
|
21
|
+
"enforce_secure_execution",
|
|
22
|
+
"empty_device_cache",
|
|
23
|
+
"preferred_dtype",
|
|
24
|
+
"resolve_default_device",
|
|
25
|
+
"resolve_device",
|
|
26
|
+
"resolve_torch_device",
|
|
27
|
+
]
|
|
File without changes
|