Text Generation
PEFT
Safetensors
Transformers
lora
research-prototype
failed-promotion
not-ready-for-deployment
Instructions to use minagayid/ELLM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use minagayid/ELLM with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("HuggingFaceTB/SmolLM2-135M-Instruct") model = PeftModel.from_pretrained(base_model, "minagayid/ELLM") - Transformers
How to use minagayid/ELLM with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="minagayid/ELLM")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("minagayid/ELLM", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use minagayid/ELLM with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "minagayid/ELLM" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "minagayid/ELLM", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/minagayid/ELLM
- SGLang
How to use minagayid/ELLM with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "minagayid/ELLM" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "minagayid/ELLM", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "minagayid/ELLM" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "minagayid/ELLM", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use minagayid/ELLM with Docker Model Runner:
docker model run hf.co/minagayid/ELLM
Download training/evaluate_adapter.py from minagayid/ELLM: direct link, hf CLI and curl.
- Browser
- Download file 8.65 kB
-
https://huggingface.co/minagayid/ELLM/resolve/main/training/evaluate_adapter.py
- Command line
-
hf download hf://minagayid/ELLM/training/evaluate_adapter.py
-
curl -L -o evaluate_adapter.py https://huggingface.co/minagayid/ELLM/resolve/main/training/evaluate_adapter.py
8.65 kB
| """Compare the pinned base and a local ELLM LoRA adapter on a JSONL split.""" | |
| from __future__ import annotations | |
| import argparse | |
| import hashlib | |
| import json | |
| import math | |
| import statistics | |
| import sys | |
| import time | |
| from datetime import datetime, timezone | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| if str(ROOT) not in sys.path: | |
| sys.path.insert(0, str(ROOT)) | |
| import torch | |
| import peft | |
| import transformers | |
| from peft import PeftModel | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| from ellm.triage import ( | |
| ADVISORY_LABELS, | |
| BASE_MODEL_ID, | |
| BASE_MODEL_REVISION, | |
| build_messages, | |
| parse_advisory_label, | |
| ) | |
| DATA_PATH = Path(__file__).resolve().parent / "data" / "test.jsonl" | |
| MAX_NEW_TOKENS = 8 | |
| def sha256(path: Path) -> str: | |
| return hashlib.sha256(path.read_bytes()).hexdigest() | |
| def load_base(tokenizer, device, dtype): | |
| return AutoModelForCausalLM.from_pretrained( | |
| BASE_MODEL_ID, | |
| revision=BASE_MODEL_REVISION, | |
| trust_remote_code=False, | |
| use_safetensors=True, | |
| torch_dtype=dtype, | |
| low_cpu_mem_usage=True, | |
| ).to(device) | |
| def predict(model, tokenizer, features, device) -> tuple[str | None, str, float]: | |
| prompt = tokenizer.apply_chat_template( | |
| build_messages(features), tokenize=False, add_generation_prompt=True | |
| ) | |
| inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to(device) | |
| started = time.perf_counter() | |
| with torch.inference_mode(): | |
| output = model.generate( | |
| **inputs, | |
| do_sample=False, | |
| max_new_tokens=MAX_NEW_TOKENS, | |
| pad_token_id=tokenizer.eos_token_id, | |
| eos_token_id=tokenizer.eos_token_id, | |
| ) | |
| elapsed_ms = (time.perf_counter() - started) * 1000 | |
| generated = output[0, inputs["input_ids"].shape[-1] :] | |
| raw = tokenizer.decode(generated, skip_special_tokens=True).strip() | |
| return parse_advisory_label(raw), raw, elapsed_ms | |
| def summarize(rows: list[dict], predictions: list[dict]) -> dict: | |
| labels = list(sorted(ADVISORY_LABELS)) | |
| confusion = { | |
| gold: {predicted: 0 for predicted in labels + ["INVALID"]} | |
| for gold in labels | |
| } | |
| invalid = 0 | |
| for row, prediction in zip(rows, predictions): | |
| gold = row["label"] | |
| pred = prediction["label"] or "INVALID" | |
| confusion[gold][pred] += 1 | |
| invalid += pred == "INVALID" | |
| class_metrics = {} | |
| f1s = [] | |
| correct = 0 | |
| for label in labels: | |
| tp = confusion[label][label] | |
| fp = sum(confusion[gold][label] for gold in labels if gold != label) | |
| fn = sum(confusion[label][pred] for pred in labels + ["INVALID"] if pred != label) | |
| precision = tp / (tp + fp) if tp + fp else 0.0 | |
| recall = tp / (tp + fn) if tp + fn else 0.0 | |
| f1 = 2 * precision * recall / (precision + recall) if precision + recall else 0.0 | |
| class_metrics[label] = {"precision": precision, "recall": recall, "f1": f1} | |
| f1s.append(f1) | |
| correct += tp | |
| non_release = sum(row["label"] != "RELEASE" for row in rows) | |
| unsupported_release = sum( | |
| row["label"] != "RELEASE" and pred["label"] == "RELEASE" | |
| for row, pred in zip(rows, predictions) | |
| ) | |
| eligible_release = sum(row["label"] == "RELEASE" for row in rows) | |
| missed_release = sum( | |
| row["label"] == "RELEASE" and pred["label"] != "RELEASE" | |
| for row, pred in zip(rows, predictions) | |
| ) | |
| latencies = sorted(prediction["latency_ms"] for prediction in predictions) | |
| p95_index = max(0, math.ceil(0.95 * len(latencies)) - 1) | |
| return { | |
| "rows": len(rows), | |
| "exact_accuracy": correct / max(len(rows), 1), | |
| "macro_f1": statistics.mean(f1s), | |
| "invalid_output_count": invalid, | |
| "per_class": class_metrics, | |
| "confusion_matrix": confusion, | |
| "unsupported_release_count": unsupported_release, | |
| "unsupported_release_rate_on_non_release": unsupported_release / max(non_release, 1), | |
| "eligible_release_miss_count": missed_release, | |
| "eligible_release_miss_rate": missed_release / max(eligible_release, 1), | |
| "predicted_release_coverage": sum(pred["label"] == "RELEASE" for pred in predictions) / max(len(rows), 1), | |
| "latency_median_ms": statistics.median(latencies) if latencies else None, | |
| "latency_p95_ms": latencies[p95_index] if latencies else None, | |
| } | |
| def evaluate_model(rows, tokenizer, device, dtype, adapter_dir: Path | None = None) -> dict: | |
| model = load_base(tokenizer, device, dtype) | |
| if adapter_dir is not None: | |
| model = PeftModel.from_pretrained( | |
| model, | |
| str(adapter_dir), | |
| local_files_only=True, | |
| is_trainable=False, | |
| ) | |
| model.eval() | |
| predictions = [] | |
| for row in rows: | |
| label, raw, latency = predict(model, tokenizer, row["features"], device) | |
| predictions.append({"label": label, "raw": raw, "latency_ms": latency}) | |
| metrics = summarize(rows, predictions) | |
| del model | |
| if device.type == "cuda": | |
| torch.cuda.empty_cache() | |
| return metrics | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument( | |
| "--data", type=Path, default=DATA_PATH, help="JSONL evaluation split" | |
| ) | |
| parser.add_argument( | |
| "--adapter-dir", type=Path, default=ROOT, help="Local adapter directory" | |
| ) | |
| parser.add_argument( | |
| "--output", | |
| type=Path, | |
| required=True, | |
| help="New result JSON path; existing files are never overwritten", | |
| ) | |
| args = parser.parse_args() | |
| if not torch.cuda.is_available(): | |
| raise RuntimeError("Evaluation requires the same local CUDA runtime as the recorded training run.") | |
| data_path = args.data.resolve() | |
| adapter_dir = args.adapter_dir.resolve() | |
| output_path = args.output.resolve() | |
| adapter_path = adapter_dir / "adapter_model.safetensors" | |
| train_run_path = adapter_dir / "training" / "run.json" | |
| if not adapter_path.is_file(): | |
| raise FileNotFoundError(f"adapter weights not found: {adapter_path}") | |
| if not train_run_path.is_file(): | |
| raise FileNotFoundError(f"training run manifest not found: {train_run_path}") | |
| if not data_path.is_file(): | |
| raise FileNotFoundError(f"evaluation data not found: {data_path}") | |
| if output_path.exists(): | |
| raise FileExistsError(f"refusing to overwrite evaluation report: {output_path}") | |
| rows = [ | |
| json.loads(line) | |
| for line in data_path.read_text(encoding="utf-8").splitlines() | |
| if line | |
| ] | |
| if not rows: | |
| raise ValueError("evaluation split is empty") | |
| device = torch.device("cuda") | |
| dtype = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float16 | |
| tokenizer = AutoTokenizer.from_pretrained( | |
| BASE_MODEL_ID, | |
| revision=BASE_MODEL_REVISION, | |
| trust_remote_code=False, | |
| use_fast=True, | |
| ) | |
| base = evaluate_model(rows, tokenizer, device, dtype) | |
| adapted = evaluate_model(rows, tokenizer, device, dtype, adapter_dir=adapter_dir) | |
| try: | |
| data_label = data_path.relative_to(ROOT).as_posix() | |
| except ValueError: | |
| data_label = data_path.name | |
| results = { | |
| "evaluation": "ELLM synthetic triage comparison v2", | |
| "created_at_utc": datetime.now(timezone.utc).isoformat(), | |
| "base_model_id": BASE_MODEL_ID, | |
| "base_model_revision": BASE_MODEL_REVISION, | |
| "base_model_license": "Apache-2.0", | |
| "evaluation_data": data_label, | |
| "evaluation_data_sha256": sha256(data_path), | |
| "training_run_sha256": sha256(train_run_path), | |
| "adapter_sha256": sha256(adapter_path), | |
| "evaluation_seed": "recorded in training/data/manifest.json when using a repository split", | |
| "device": torch.cuda.get_device_name(0), | |
| "torch_version": torch.__version__, | |
| "transformers_version": transformers.__version__, | |
| "peft_version": peft.__version__, | |
| "python_version": sys.version, | |
| "generation": {"do_sample": False, "max_new_tokens": MAX_NEW_TOKENS}, | |
| "base_only": base, | |
| "base_plus_candidate_adapter": adapted, | |
| "scope": "Descriptive results on procedurally generated, closed-world policy labels only. Not a factuality, source-verification, 30-day waiting, multilingual, or real-world safety evaluation.", | |
| } | |
| output_path.parent.mkdir(parents=True, exist_ok=True) | |
| output_path.write_text(json.dumps(results, indent=2, ensure_ascii=False) + "\n", encoding="utf-8") | |
| print(json.dumps(results, indent=2, ensure_ascii=False)) | |
| if __name__ == "__main__": | |
| main() | |