|
|
import torch |
|
|
from cognitive_mapping_probe.llm_iface import get_or_load_model |
|
|
from cognitive_mapping_probe.resonance_seismograph import run_silent_cogitation_seismic |
|
|
from cognitive_mapping_probe.concepts import get_concept_vector, _get_last_token_hidden_state |
|
|
|
|
|
def test_get_or_load_model_loads_correctly(model_id): |
|
|
"""Testet, ob das Laden eines echten Modells funktioniert.""" |
|
|
llm = get_or_load_model(model_id, seed=42) |
|
|
assert llm is not None |
|
|
assert llm.model_id == model_id |
|
|
assert llm.stable_config.hidden_dim > 0 |
|
|
assert llm.stable_config.num_layers > 0 |
|
|
|
|
|
def test_run_silent_cogitation_seismic_output_shape_and_type(model_id): |
|
|
"""Führt einen kurzen Lauf mit einem echten Modell durch und prüft die Datentypen.""" |
|
|
num_steps = 5 |
|
|
llm = get_or_load_model(model_id, seed=42) |
|
|
state_deltas = run_silent_cogitation_seismic( |
|
|
llm=llm, prompt_type="control_long_prose", |
|
|
num_steps=num_steps, temperature=0.1 |
|
|
) |
|
|
assert isinstance(state_deltas, list) |
|
|
assert len(state_deltas) == num_steps |
|
|
assert all(isinstance(d, float) for d in state_deltas) |
|
|
|
|
|
def test_get_last_token_hidden_state_robustness(model_id): |
|
|
"""Testet die Helper-Funktion mit einem echten Modell.""" |
|
|
llm = get_or_load_model(model_id, seed=42) |
|
|
hs = _get_last_token_hidden_state(llm, "test prompt") |
|
|
assert isinstance(hs, torch.Tensor) |
|
|
assert hs.shape == (llm.stable_config.hidden_dim,) |
|
|
|
|
|
def test_get_concept_vector_logic(model_id): |
|
|
"""Testet die Vektor-Extraktion mit einem echten Modell.""" |
|
|
llm = get_or_load_model(model_id, seed=42) |
|
|
|
|
|
vector = get_concept_vector(llm, "love", baseline_words=["thing", "place"]) |
|
|
assert isinstance(vector, torch.Tensor) |
|
|
assert vector.shape == (llm.stable_config.hidden_dim,) |
|
|
|