-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli_flags.py
More file actions
84 lines (69 loc) · 2 KB
/
test_cli_flags.py
File metadata and controls
84 lines (69 loc) · 2 KB
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
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
"""Smoke tests that cover `t81-convert`/`t81-gguf` flag combinations."""
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
from transformers import AutoModelForSequenceClassification, BertConfig
def _build_dummy_hf_model(directory: Path) -> None:
config = BertConfig(
vocab_size=64,
hidden_size=32,
num_attention_heads=4,
intermediate_size=64,
num_hidden_layers=1,
num_labels=2,
)
model = AutoModelForSequenceClassification.from_config(config)
model.save_pretrained(directory)
def _run_convert(source: Path, target: Path) -> None:
cmd = [
sys.executable,
"-m",
"t81",
"convert",
str(source),
str(target),
"--device-map",
"none",
"--force-cpu-device-map",
"--torch-dtype",
"float16",
]
subprocess.run(cmd, check=True)
def _run_gguf(source: Path, gguf_path: Path) -> None:
cmd = [
sys.executable,
"-m",
"t81",
"gguf",
str(gguf_path),
"--from-hf",
str(source),
"--device-map",
"none",
"--force-cpu-device-map",
"--torch-dtype",
"float16",
"--quant",
"TQ2_0",
]
subprocess.run(cmd, check=True)
def _run_info(path: Path) -> None:
cmd = [sys.executable, "-m", "t81", "info", str(path)]
subprocess.run(cmd, check=True)
def test_convert_respects_flags(tmp_path: Path) -> None:
source = tmp_path / "hf"
target = tmp_path / "converted"
source.mkdir()
_build_dummy_hf_model(source)
_run_convert(source, target)
assert (target / "t81_metadata.json").exists()
_run_info(target)
def test_gguf_respects_device_map(tmp_path: Path) -> None:
source = tmp_path / "hf"
gguf_file = tmp_path / "model.gguf"
source.mkdir()
_build_dummy_hf_model(source)
_run_gguf(source, gguf_file)
assert gguf_file.exists() and gguf_file.stat().st_size > 0
_run_info(gguf_file)