Views
No views yet
TinyLlama/TinyLlama-1.1B-Chat-v1.0.💡 This repo contains only the early-exit heads + a small loader. You must also have the base model (it downloads automatically in the examples below).
max_prob >= confidence_threshold, exit early.1# pip install -U torch transformers safetensors huggingface_hub
2
3from huggingface_hub import hf_hub_download
4import importlib.util, sys
5
6REPO_ID = "5ivatej/tinyllama-1.1b-early-exit"
7
8# 1) Dynamically fetch the loader from the Hub
9module_path = hf_hub_download(REPO_ID, "early_exit_wrapper.py")
10
11# 2) Import it as a module
12spec = importlib.util.spec_from_file_location("early_exit_wrapper", module_path)
13early = importlib.util.module_from_spec(spec); sys.modules["early_exit_wrapper"] = early
14spec.loader.exec_module(early)
15
16# 3) Load wrapped model + tokenizer
17wrapped, tok = early.load_early_exit_from_hub(REPO_ID) # auto-picks CPU/MPS/CUDA & safe dtype
18
19# 4) Generate with early exit
20ids = early.generate_with_early_exit(
21 "Explain early exit in one tweet.",
22 wrapped, tok,
23 max_new_tokens=64, temperature=0.7, top_p=0.9
24)
25print(tok.decode(ids[0], skip_special_tokens=True))