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 compare.py from HyperionGrayAI/cybermodels-fused: direct link, hf CLI and curl.
- Browser
- Download file 3.42 kB
-
https://huggingface.co/HyperionGrayAI/cybermodels-fused/resolve/main/compare.py
- Command line
-
hf download hf://HyperionGrayAI/cybermodels-fused/compare.py
-
curl -L -o compare.py https://huggingface.co/HyperionGrayAI/cybermodels-fused/resolve/main/compare.py
3.42 kB
| """Compare the bare reference and fused adapter on identical evidence and decoding settings.""" | |
| import argparse | |
| import json | |
| import time | |
| from contextlib import nullcontext | |
| from pathlib import Path | |
| import peft | |
| import torch | |
| import transformers | |
| from ask import BASE, REVISION, generate, load | |
| from team_brief import brief | |
| ROOT = Path(__file__).resolve().parent | |
| def emit(data): | |
| print("CYBERMODELS_RESULT " + json.dumps(data, ensure_ascii=False), flush=True) | |
| def compare(args): | |
| if args.device == "cpu": | |
| torch.set_num_threads(args.threads) | |
| start = time.monotonic() | |
| model, tok = load(args.base, args.revision, args.device) | |
| model = peft.PeftModel.from_pretrained( | |
| model, args.adapter, revision=args.adapter_revision | |
| ).eval() | |
| devices = {} | |
| for p in model.parameters(): | |
| device = str(p.device) | |
| devices[device] = devices.get(device, 0) + p.numel() * p.element_size() | |
| if args.device == "cuda" and any( | |
| not device.startswith("cuda:") for device in devices | |
| ): | |
| raise ValueError("Base and adapter must both reside on CUDA") | |
| emit( | |
| { | |
| "type": "placement", | |
| "load_seconds": round(time.monotonic() - start, 2), | |
| "device_parameter_bytes": devices, | |
| "torch": torch.__version__, | |
| "transformers": transformers.__version__, | |
| "peft": peft.__version__, | |
| "experts_per_token": model.config.num_experts_per_tok, | |
| "expert_count": model.config.num_experts, | |
| "cuda_devices": [ | |
| torch.cuda.get_device_name(i) for i in range(torch.cuda.device_count()) | |
| ] | |
| if args.device == "cuda" | |
| else [], | |
| "dtype": str(model.get_input_embeddings().weight.dtype), | |
| } | |
| ) | |
| for enabled in [False, True]: | |
| with nullcontext() if enabled else model.disable_adapter(): | |
| generate(model, tok, "Reply with the digit 7.", 2) | |
| for i, case in enumerate(json.loads((ROOT / "cases.json").read_text())): | |
| question = brief(ROOT, case["question"]) | |
| for enabled in [False, True] if i % 2 == 0 else [True, False]: | |
| with nullcontext() if enabled else model.disable_adapter(): | |
| start = time.monotonic() | |
| answer, inputs, output = generate(model, tok, question, args.max_tokens) | |
| elapsed = time.monotonic() - start | |
| emit( | |
| { | |
| "type": "answer", | |
| "case": case["id"], | |
| "mode": "fused" if enabled else "plain", | |
| "input_tokens": inputs, | |
| "output_tokens": output, | |
| "max_tokens": args.max_tokens, | |
| "seconds": round(elapsed, 3), | |
| "answer": answer, | |
| } | |
| ) | |
| emit({"type": "complete"}) | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--base", default=BASE) | |
| parser.add_argument("--revision", default=REVISION) | |
| parser.add_argument("--adapter", default=str(ROOT)) | |
| parser.add_argument("--adapter-revision", default=REVISION) | |
| parser.add_argument("--device", choices=["cuda", "cpu"], default="cuda") | |
| parser.add_argument("--max-tokens", type=int, default=240) | |
| parser.add_argument("--threads", type=int, default=12) | |
| compare(parser.parse_args()) | |