frankmorales2020 commited on
Commit
4abdd5f
·
verified ·
1 Parent(s): 5af07ca

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +75 -0
README.md CHANGED
@@ -93,6 +93,81 @@ The
93
 
94
  =================================================================
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
 
 
97
 
98
  ```
 
93
 
94
  =================================================================
95
 
96
+ ```
97
+
98
+ ```python
99
+ # Run once, then RESTART RUNTIME, then run this cell:
100
+ # !pip install -q "compressed-tensors>=0.15.0"
101
+
102
+ import warnings, logging, os
103
+ warnings.filterwarnings("ignore")
104
+ logging.getLogger("transformers").setLevel(logging.ERROR)
105
+ os.environ["TRANSFORMERS_VERBOSITY"] = "error"
106
+ os.environ["TRANSFORMERS_NO_ADVISORY_WARNINGS"] = "1"
107
+ try:
108
+ from transformers.utils import logging as _hf_log
109
+ _hf_log.set_verbosity_error()
110
+ except Exception:
111
+ pass
112
+
113
+ import transformers.utils.import_utils as _iu
114
+ import transformers.utils as _tu
115
+ for _m in (_iu, _tu):
116
+ if not hasattr(_m, "is_torch_fx_available"):
117
+ _m.is_torch_fx_available = lambda: False
118
+
119
+ import torch
120
+ from transformers import AutoModelForCausalLM, AutoTokenizer
121
+ import transformers.modeling_utils as _mu
122
+
123
+ # FP8 fix: skip re-init of already-loaded FP8 weights.
124
+ _mu.PreTrainedModel._initialize_weights = lambda self, *a, **k: None
125
+ _mu.PreTrainedModel.initialize_weights = lambda self, *a, **k: None
126
+
127
+ REPO = "frankmorales2020/deepseek-v2-lite-fp8-topo2026"
128
+ PROMPTS = ["What is the capital of Japan?",
129
+ "What is the Spanish word for water?",
130
+ "What is Einstein's mass-energy equivalence?"]
131
+
132
+ try:
133
+ tok = AutoTokenizer.from_pretrained(REPO, trust_remote_code=True)
134
+ except Exception:
135
+ tok = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-V2-Lite", trust_remote_code=True)
136
+ if tok.pad_token is None:
137
+ tok.pad_token = tok.eos_token
138
+
139
+ model = AutoModelForCausalLM.from_pretrained(
140
+ REPO, dtype=torch.float16, device_map="auto",
141
+ trust_remote_code=True, attn_implementation="eager").eval()
142
+
143
+ nan = torch.isnan(model.get_input_embeddings().weight.float()).any().item()
144
+ print("Embedding has NaN?", nan)
145
+
146
+ if not nan:
147
+ for p in PROMPTS:
148
+ ins = tok(p, return_tensors="pt").to(model.device)
149
+ out = model.generate(**ins, max_new_tokens=40, do_sample=False,
150
+ repetition_penalty=1.2, no_repeat_ngram_size=3,
151
+ use_cache=False,
152
+ pad_token_id=tok.pad_token_id)
153
+ txt = tok.decode(out[0], skip_special_tokens=True)
154
+ print(f"\nQ: {p}\nA: {txt[len(p):].strip() if txt.startswith(p) else txt.strip()}")
155
+
156
+ ```
157
+ OUTPUT-EXPECTED
158
+
159
+ ```text
160
+ Compressing model: 100%|██████████| 3463/3463 [00:01<00:00, 1977.29it/s]
161
+ Loading weights: 100% 12217/12217 [00:01<00:00, 8114.97it/s]Embedding has NaN? False
162
+ Decompressing model: 100%|██████████| 3463/3463 [00:00<00:00, 13103.20it/s]
163
+
164
+ Q: What is the capital of Japan?
165
+ A: The answer to this question may seem obvious, but it’s actually a bit more complicated than you might think. The country has two capitals: Tokyo and Kyoto. Both cities are important in Japanese
166
+
167
+ Q: What is the Spanish word for water?
168
+ A: The English translation of “agua” in a sentence. Agua means Water, and it’s pronounced like this: ah-gwah (like how you say ‘gwa’
169
 
170
+ Q: What is Einstein's mass-energy equivalence?
171
+ A: Einstein’s Mass Energy Equivalence states that the energy of a body at rest (E) equals its mass times the speed of light squared. This equation can be written as: E = mc
172
 
173
  ```