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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
:
:
:
:
:
...
"""BitLlama model wrapper for inference.
Args:
config: BitLlamaConfig object with model configuration
checkpoint_path: Path to the model checkpoint file (.safetensors)
device: Device to run on ("cpu" or "cuda"). Defaults to "cpu"
tokenizer_path: Path to tokenizer.json file for text encoding/decoding
"""
...
"""Forward pass on a single token.
Args:
token_id: Token ID to process
Returns:
Logits over the vocabulary
"""
...
"""Generate text from a prompt.
Requires tokenizer to be loaded during initialization.
Args:
prompt: Input text prompt
max_tokens: Maximum number of tokens to generate
Returns:
Generated text (excluding the prompt)
Raises:
ValueError: If tokenizer was not provided during initialization
"""
...
"""Generate tokens from a list of starting token IDs.
Args:
start_tokens: List of token IDs to start from
max_new_tokens: Maximum number of new tokens to generate
Returns:
Full list of tokens (prompt + generated)
"""
...
"""BitLlama trainer for model training."""
...
"""Set the learning rate for the optimizer."""
...
"""Execute one training step.
Args:
py_input_ids: Input token IDs
py_targets: Target token IDs (labels)
Returns:
Loss value for this step
"""
...
"""Save model checkpoint and optimizer state.
Args:
path: Path to save checkpoint (creates .safetensors and .safetensors.optim files)
"""
...