mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-09 22:13:43 +08:00
22a8575199
Keep official openpilot ancestry and dependency licenses. Store resources directly in Git, remove LFS setup requirements, and leave the downloadable big model outside the source tree.
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from tinygrad import nn, Tensor, dtypes
|
|
from tinygrad.helpers import DEV, Timing, Context
|
|
|
|
from extra.models.llama import Transformer
|
|
from examples.llama3 import MODEL_PARAMS
|
|
|
|
if __name__ == "__main__":
|
|
DEV.value = "NULL"
|
|
#model_size = "8B"
|
|
model_size = "405B"
|
|
|
|
with Context(TRAINING=1), Timing("total "):
|
|
with Timing("***** create model in "):
|
|
model = Transformer(**MODEL_PARAMS[model_size]["args"], linear=nn.Linear, embedding=nn.Embedding,
|
|
max_context=1024, jit=True, disable_kv_cache=True)
|
|
|
|
with Timing("***** fake state in "):
|
|
Tensor.realize(*[p.assign(Tensor.empty(*p.shape, device=p.device, dtype=p.dtype)) for p in nn.state.get_parameters(model)])
|
|
|
|
with Timing("***** create optim in "):
|
|
opt = nn.optim.AdamW(nn.state.get_parameters(model))
|
|
|
|
with Timing("***** run model in "):
|
|
toks = Tensor.empty(1, 1024, dtype=dtypes.int)
|
|
out = model(toks, 0, temperature=float('nan'))
|
|
|
|
with Timing("***** backward in "):
|
|
out.mean().backward()
|
|
|
|
with Timing("***** realize in "):
|
|
out.realize()
|
|
|
|
with Timing("***** step in "):
|
|
opt.step()
|