Text Classification
Transformers
Safetensors
PEFT
branchone
feature-extraction
decision-model
multimodal
custom-code
custom_code
Instructions to use ndemirdemir/BranchOne with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ndemirdemir/BranchOne with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="ndemirdemir/BranchOne", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("ndemirdemir/BranchOne", trust_remote_code=True, device_map="auto") - PEFT
How to use ndemirdemir/BranchOne with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Download calibration.py from ndemirdemir/BranchOne: direct link, hf CLI and curl.
- Browser
- Download file 4.39 kB
-
https://huggingface.co/ndemirdemir/BranchOne/resolve/main/calibration.py
- Command line
-
hf download hf://ndemirdemir/BranchOne/calibration.py
-
curl -L -o calibration.py https://huggingface.co/ndemirdemir/BranchOne/resolve/main/calibration.py
4.39 kB
| """Validate calibration against every serving input before constructing a model.""" | |
| import json | |
| import math | |
| import re | |
| from pathlib import Path | |
| from .io import sha256 | |
| BACKEND = "hf-adapter-fp16" | |
| UNFITTED = "unfitted for v2" | |
| FITTED = "fitted on the supplied calibration split only" | |
| SERVING_FILES = ( | |
| "model_config.json", | |
| "head.safetensors", | |
| "adapter/adapter_config.json", | |
| "adapter/adapter_model.safetensors", | |
| "processor/tokenizer.json", | |
| "processor/tokenizer_config.json", | |
| "processor/processor_config.json", | |
| "processor/chat_template.jinja", | |
| ) | |
| LEGACY_FILES = ( | |
| "head.safetensors", | |
| "adapter/adapter_model.safetensors", | |
| "model_config.json", | |
| ) | |
| def positive_temperature(value): | |
| try: | |
| valid = type(value) in (int, float) and math.isfinite(value) and value > 0 | |
| except OverflowError: | |
| valid = False | |
| if not valid: | |
| raise ValueError("Calibration temperature must be finite and positive") | |
| return float(value) | |
| def model_identity(checkpoint): | |
| """Legacy identity retained for compatibility with completed result audits.""" | |
| return {name: sha256(Path(checkpoint) / name) for name in LEGACY_FILES} | |
| def serving_identity(checkpoint): | |
| root = Path(checkpoint).resolve() | |
| files = {} | |
| for name in SERVING_FILES: | |
| path = root / name | |
| if ( | |
| path.is_symlink() | |
| or not path.resolve().is_relative_to(root) | |
| or not path.is_file() | |
| ): | |
| raise ValueError("Missing or unsafe serving file: " + name) | |
| files[name] = sha256(path) | |
| return {"version": 1, "files": files} | |
| def validate_calibration(checkpoint, value, *, backend=BACKEND): | |
| required = { | |
| "temperature", | |
| "status", | |
| "model_files", | |
| "backend", | |
| "data_sha256", | |
| "n", | |
| "serving_identity", | |
| } | |
| if not isinstance(value, dict) or set(value) != required: | |
| raise ValueError( | |
| "Calibration requires versioned serving-file provenance; legacy " | |
| "metadata must be upgraded using verified evaluation evidence" | |
| ) | |
| positive_temperature(value["temperature"]) | |
| if backend != BACKEND or value["backend"] != backend: | |
| raise ValueError("Calibration backend is not qualified") | |
| if value["status"] != FITTED: | |
| raise ValueError("Calibration must record a fitted calibration split") | |
| if type(value["n"]) is not int or value["n"] <= 0: | |
| raise ValueError("Calibration example count must be a positive integer") | |
| if not isinstance(value["data_sha256"], str) or not re.fullmatch( | |
| r"[0-9a-f]{64}", value["data_sha256"] | |
| ): | |
| raise ValueError("Calibration data identity must be a SHA256 digest") | |
| binding = value["serving_identity"] | |
| if ( | |
| not isinstance(binding, dict) | |
| or set(binding) != {"version", "files"} | |
| or type(binding["version"]) is not int | |
| or binding["version"] != 1 | |
| ): | |
| raise ValueError("Unsupported calibration serving identity") | |
| actual = serving_identity(checkpoint) | |
| if binding != actual: | |
| raise ValueError("Calibration was fitted for different serving files") | |
| if value["model_files"] != {name: actual["files"][name] for name in LEGACY_FILES}: | |
| raise ValueError("Calibration has a stale legacy model identity") | |
| return value | |
| def load_calibration(checkpoint, path, *, backend=BACKEND): | |
| try: | |
| value = json.loads(Path(path).read_text()) | |
| except (OSError, ValueError) as error: | |
| raise ValueError("Cannot read calibration metadata") from error | |
| return validate_calibration(checkpoint, value, backend=backend) | |
| def checkpoint_calibration(checkpoint, config, *, trainable=False): | |
| """Training starts unfitted; serving requires either unit T or valid binding.""" | |
| if trainable: | |
| return 1.0, UNFITTED | |
| path = Path(checkpoint) / "calibration.json" | |
| if path.exists(): | |
| value = load_calibration(checkpoint, path) | |
| return positive_temperature(value["temperature"]), value["status"] | |
| temperature = positive_temperature(config.get("temperature")) | |
| status = config.get("calibration_status") | |
| if ( | |
| temperature != 1.0 | |
| or not isinstance(status, str) | |
| or not status.startswith("unfitted") | |
| ): | |
| raise ValueError("Serving calibration is missing its verified binding") | |
| return 1.0, UNFITTED | |