Instructions to use HyperionGrayAI/cybermodels-fused with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use HyperionGrayAI/cybermodels-fused with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("HyperionGrayAI/qwennifer-flash-bf16") model = PeftModel.from_pretrained(base_model, "HyperionGrayAI/cybermodels-fused") - Notebooks
- Google Colab
- Kaggle
Download ask.py from HyperionGrayAI/cybermodels-fused: direct link, hf CLI and curl.
- Browser
- Download file 3.02 kB
-
https://huggingface.co/HyperionGrayAI/cybermodels-fused/resolve/main/ask.py
- Command line
-
hf download hf://HyperionGrayAI/cybermodels-fused/ask.py
-
curl -L -o ask.py https://huggingface.co/HyperionGrayAI/cybermodels-fused/resolve/main/ask.py
3.02 kB
| """Generate an answer with a GPU-resident stock Transformers BF16 reference.""" | |
| import argparse | |
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| BASE = "HyperionGrayAI/qwennifer-flash-bf16" | |
| REVISION = "v0.1" | |
| def load(base=BASE, revision=REVISION, device="cuda"): | |
| if device == "cuda" and not torch.cuda.is_available(): | |
| raise RuntimeError( | |
| "CUDA is required for GPU-resident serving. For a host-memory control, choose --device cpu." | |
| ) | |
| kwargs = {"revision": revision, "dtype": torch.bfloat16, "trust_remote_code": False} | |
| tokenizer = AutoTokenizer.from_pretrained( | |
| base, revision=revision, trust_remote_code=False | |
| ) | |
| if device == "cuda": | |
| free = [torch.cuda.mem_get_info(i)[0] for i in range(torch.cuda.device_count())] | |
| if sum(free) < 159348782592: | |
| raise RuntimeError( | |
| "The BF16 weights alone need 148.4 GiB. Supply enough free GPU memory plus room for context." | |
| ) | |
| kwargs["device_map"] = "auto" | |
| else: | |
| kwargs["device_map"] = {"": "cpu"} | |
| model = AutoModelForCausalLM.from_pretrained(base, **kwargs).eval() | |
| if model.config.num_experts_per_tok != 6: | |
| raise ValueError("The model configuration must route six experts per token.") | |
| if device == "cuda" and ( | |
| any(p.device.type != "cuda" for p in model.parameters()) | |
| or any(str(d) in ("cpu", "disk", "meta") for d in model.hf_device_map.values()) | |
| ): | |
| raise RuntimeError( | |
| "The device map offloaded part of the checkpoint. Provide more GPU memory or use --device cpu." | |
| ) | |
| return model, tokenizer | |
| def generate(model, tokenizer, question, max_tokens): | |
| text = tokenizer.apply_chat_template( | |
| [{"role": "user", "content": question}], | |
| tokenize=False, | |
| add_generation_prompt=True, | |
| ) | |
| inputs = tokenizer(text, add_special_tokens=False, return_tensors="pt").to( | |
| model.get_input_embeddings().weight.device | |
| ) | |
| output = model.generate(**inputs, max_new_tokens=max_tokens, do_sample=False) | |
| suffix = output[0, inputs.input_ids.shape[1] :] | |
| return ( | |
| tokenizer.decode(suffix, skip_special_tokens=True), | |
| int(inputs.input_ids.shape[1]), | |
| int(suffix.numel()), | |
| ) | |
| if __name__ == "__main__": | |
| p = argparse.ArgumentParser(description=__doc__) | |
| p.add_argument("question") | |
| p.add_argument("--adapter", help="PEFT adapter directory or Hub model ID") | |
| p.add_argument("--adapter-revision", default="v0.1") | |
| p.add_argument("--max-tokens", type=int, default=160) | |
| p.add_argument("--device", choices=["cuda", "cpu"], default="cuda") | |
| args = p.parse_args() | |
| model, tokenizer = load(device=args.device) | |
| if args.adapter: | |
| from peft import PeftModel | |
| model = PeftModel.from_pretrained( | |
| model, args.adapter, revision=args.adapter_revision | |
| ).eval() | |
| print(generate(model, tokenizer, args.question, args.max_tokens)[0]) | |