# 1) install + auth (private repo)# !pip install -q "transformers>=4.50" huggingface_hub safetensorsfrom huggingface_hub import login, snapshot_downloadlogin() # 2) download repo (weights + tokenizer + modeling package)local = snapshot_download(repo_id="kshitijthakkar/deepseek-v4-mini-1B-from-flash") # 3) register the deepseek_v4 model_type with HF auto classesimport sys, ossys.path.insert(0, os.path.join(local, "code"))import deepseek_v4 # noqa: F401 — side-effect: AutoConfig / AutoModelForCausalLM registration # 4) load via the standard Auto APIimport torchfrom transformers import AutoModelForCausalLM, AutoTokenizer tok = AutoTokenizer.from_pretrained(local)model = AutoModelForCausalLM.from_pretrained(local, torch_dtype=torch.bfloat16)model.eval() # 5) chat-templated forward pass — initial loss is much lower than the# random-init scaffold, but the compressor/indexer paths are still random# until you fine-tune (see below).messages = [{"role": "user", "content": "Hello"}]ids = tok.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True, return_dict=True)with torch.no_grad(): print(model(input_ids=ids["input_ids"]).logits.shape)