File size: 1,831 Bytes
a345062
c0f4adf
a345062
d407fda
a345062
c0f4adf
 
 
 
 
 
 
a345062
c0f4adf
 
8489475
c0f4adf
 
 
 
8489475
c0f4adf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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)
    # Verwende eine sehr kurze Baseline für einen schnellen Test
    vector = get_concept_vector(llm, "love", baseline_words=["thing", "place"])
    assert isinstance(vector, torch.Tensor)
    assert vector.shape == (llm.stable_config.hidden_dim,)