frankmorales2020 commited on
Commit
c1bc827
Β·
verified Β·
1 Parent(s): 88db8d8

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +98 -0
README.md ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+
4
+ ## FP8 Compress
5
+
6
+ ```python
7
+
8
+ # ============================================================================
9
+ # MIXTRAL 8x7B β€” FP8 COMPRESSION WITH LLMCOMPRESSOR
10
+ # ============================================================================
11
+ # INSTRUCTIONS β€” run these cells IN ORDER in a fresh Colab session:
12
+ #
13
+ # CELL 1 (installs β€” run first, then RESTART RUNTIME):
14
+ # -------------------------------------------------------
15
+ # !pip uninstall torchvision -y
16
+ # !pip install llmcompressor==0.4.2 -q
17
+ # !pip install torch==2.4.1 torchvision==0.19.1 --index-url https://download.pytorch.org/whl/cu121 -q
18
+ #
19
+ # CELL 2 (compression β€” run after restart):
20
+ # -------------------------------------------------------
21
+ # [paste everything below this line]
22
+ # ============================================================================
23
+
24
+ from transformers import AutoModelForCausalLM, AutoTokenizer
25
+ from llmcompressor import oneshot
26
+ from llmcompressor.modifiers.quantization import QuantizationModifier
27
+ import torch, os
28
+
29
+ print(f"torch={torch.__version__}")
30
+
31
+ MODEL_ID = "mistralai/Mixtral-8x7B-v0.1"
32
+ SAVE_DIR = "/content/mixtral-8x7b-fp8-topo2026"
33
+ HF_REPO = "frankmorales2020/mixtral-8x7b-fp8-topo2026"
34
+
35
+ # ── Load ─────────────────────────────────────────────────────────────────────
36
+ print(f"\n[COMPRESS] Loading {MODEL_ID}...")
37
+ model = AutoModelForCausalLM.from_pretrained(
38
+ MODEL_ID,
39
+ device_map="auto",
40
+ torch_dtype="auto",
41
+ trust_remote_code=True,
42
+ )
43
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
44
+ if tokenizer.pad_token is None:
45
+ tokenizer.pad_token = tokenizer.eos_token
46
+ print("[COMPRESS] Loaded.")
47
+
48
+ # ── Recipe ───────────────────────────────────────────────────────────────────
49
+ # re:.*embed.* excluded β†’ embedding matrix stays BF16 β€” CRITICAL for TOPO-2026
50
+ # re:.*gate.* excluded β†’ MoE routers stay BF16
51
+ recipe = QuantizationModifier(
52
+ targets="Linear",
53
+ scheme="FP8",
54
+ ignore=["lm_head", "re:.*gate.*", "re:.*embed.*"]
55
+ )
56
+
57
+ print("\n[COMPRESS] Recipe: FP8 | ignore: lm_head, gates, embeddings")
58
+
59
+ # ── Compress ─────────────────────────────────────────────────────────────────
60
+ print("\n[COMPRESS] Running oneshot (512 calibration samples)...")
61
+ oneshot(
62
+ model=model,
63
+ recipe=recipe,
64
+ tokenizer=tokenizer,
65
+ dataset="open_platypus",
66
+ num_calibration_samples=512,
67
+ max_seq_length=2048,
68
+ )
69
+ print("[COMPRESS] Done.")
70
+
71
+ # ── Save ─────────────────────────────────────────────────────────────────────
72
+ os.makedirs(SAVE_DIR, exist_ok=True)
73
+ model.save_pretrained(SAVE_DIR, save_compressed=True)
74
+ tokenizer.save_pretrained(SAVE_DIR)
75
+ print(f"[COMPRESS] Saved to {SAVE_DIR}")
76
+
77
+ # ── Push to Hub ───────────────────────────────────────────────────────────────
78
+ from huggingface_hub import login, create_repo, upload_folder
79
+ try:
80
+ from google.colab import userdata
81
+ HF_TOKEN = userdata.get('HF_TOKEN')
82
+ except Exception:
83
+ HF_TOKEN = None
84
+
85
+ login(token=HF_TOKEN, add_to_git_credential=True)
86
+ create_repo(repo_id=HF_REPO, repo_type="model", exist_ok=True,
87
+ private=False, token=HF_TOKEN)
88
+ upload_folder(
89
+ repo_id=HF_REPO, folder_path=SAVE_DIR, repo_type="model",
90
+ token=HF_TOKEN,
91
+ commit_message=(
92
+ "Mixtral-8x7B FP8 TOPO-2026 | "
93
+ "Embeddings BF16 | MoE gates BF16 | LLMCompressor"
94
+ )
95
+ )
96
+ print(f"\n✨ https://huggingface.co/{HF_REPO}")
97
+
98
+ ```