MCPcopy Create free account
hub / github.com/RightNow-AI/TIDE / TinyModel

Class TinyModel

tests/test_calibrate.py:64–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62
63
64class TinyModel(nn.Module):
65 def __init__(self, num_layers=8, dim=64, vocab_size=256):
66 super().__init__()
67 self.config = TinyConfig()
68 self.config.vocab_size = vocab_size
69 self.model = nn.Module()
70 self.model.embed_tokens = nn.Embedding(vocab_size, dim)
71 self.model.layers = nn.ModuleList([TinyDecoderLayer(dim) for _ in range(num_layers)])
72 self.model.norm = TinyRMSNorm(dim)
73 self.lm_head = nn.Linear(dim, vocab_size, bias=False)
74 self._n_layers = num_layers
75
76 def forward(self, input_ids=None, attention_mask=None, output_hidden_states=False,
77 return_dict=False, use_cache=False, past_key_values=None, **kwargs):
78 x = self.model.embed_tokens(input_ids)
79 hidden_states = [x] if output_hidden_states else None
80
81 for layer in self.model.layers:
82 x = layer(x)[0]
83 if output_hidden_states:
84 hidden_states.append(x)
85
86 logits = self.lm_head(self.model.norm(x))
87
88 cache = past_key_values if past_key_values is not None else _TinyCache(self._n_layers)
89
90 return _TinyOutput(
91 logits=logits,
92 hidden_states=tuple(hidden_states) if hidden_states else None,
93 past_key_values=cache if use_cache else None,
94 )
95
96 def __class_getitem__(cls, item):
97 return cls
98
99
100class TinyAdapter(BaseAdapter):

Callers 12

tiny_runtimeFunction · 0.90
test_get_layersMethod · 0.90
test_get_hidden_stateMethod · 0.90
test_get_final_normMethod · 0.90
test_get_lm_headMethod · 0.90
test_get_embeddingMethod · 0.90
tiny_setupFunction · 0.85

Calls

no outgoing calls

Tested by 12

tiny_runtimeFunction · 0.72
test_get_layersMethod · 0.72
test_get_hidden_stateMethod · 0.72
test_get_final_normMethod · 0.72
test_get_lm_headMethod · 0.72
test_get_embeddingMethod · 0.72
tiny_setupFunction · 0.68