File size: 1,610 Bytes
669597a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
"""The model backends: laziness, device choice, and honest failures."""

import pytest

from tiny_computer_agent import (DEFAULT_TEXT_MODEL, DEFAULT_VISION_MODEL, MODEL_BRAINS,
                                 BrainError, make_model_brain, model_cached, model_dependencies,
                                 pick_dtype, resolve_device)


def test_building_a_brain_does_not_load_any_weights():
    """Constructing must be free: --doctor builds one on machines with no cache."""
    for name in MODEL_BRAINS:
        brain = make_model_brain(name)
        assert brain.loaded is False
        assert brain.model_id in (DEFAULT_TEXT_MODEL, DEFAULT_VISION_MODEL)


def test_unload_returns_a_brain_to_the_unloaded_state():
    brain = make_model_brain("text-planner")
    brain.unload()
    assert brain.loaded is False


def test_an_unknown_brain_name_is_refused_with_the_alternatives():
    with pytest.raises(BrainError, match="unknown brain"):
        make_model_brain("gpt-9")


def test_the_text_planner_needs_an_index_but_the_vlm_does_not():
    assert make_model_brain("text-planner").requires_index is True
    assert make_model_brain("vlm").requires_index is False


def test_the_model_runtime_report_is_a_pair():
    ok, detail = model_dependencies()
    assert isinstance(ok, bool) and detail


def test_model_cached_is_false_for_a_model_that_cannot_exist():
    assert model_cached("definitely/not-a-real-model") is False


def test_device_and_dtype_are_chosen_without_a_gpu():
    assert resolve_device("cpu") == "cpu"
    assert pick_dtype("cpu") is not None
    assert pick_dtype("cuda") is not None