Run this model with HF Jobs

Run LiquidAI/d1-2B on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs and TRL to fine-tune https://huggingface.co/LiquidAI/d1-2B. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/LiquidAI/d1-2B on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

Evaluate on a benchmark

Use HF Jobs to evaluate https://huggingface.co/LiquidAI/d1-2B. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.

Quantize for lower memory use

Use HF Jobs to create a 4-bit version of https://huggingface.co/LiquidAI/d1-2B. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
d1-2B / grid.py
paulpak58's picture mlabonne's picture Aurelien-Lac's picture
d1-2B
97c5704
Raw History Blame
1.71 kB
"""Ordered values read as a distribution over equally spaced bins."""
from __future__ import annotations
import math
from collections.abc import Callable
from dataclasses import dataclass
from functools import cached_property
from typing import Sequence
@dataclass(frozen=True)
class Grid:
low: float
high: float
size: int = 128
def __post_init__(self):
if self.size < 2 or not self.low < self.high:
raise ValueError("a grid needs two values or more, low to high")
@property
def step(self) -> float:
return (self.high - self.low) / (self.size - 1)
@cached_property
def values(self) -> tuple[float, ...]:
return tuple(self.low + i * self.step for i in range(self.size - 1)) + (self.high,)
def read(self, probabilities: Sequence[float], level: Callable[[float], float] | None = None) -> dict[str, float]:
"""The mean, median and central 80 percent interval, on this grid's values; `level`, the level a quantile is
read at (a calibration's, increasing)."""
total = math.fsum(probabilities)
values = self.values
out = {"mean": math.fsum(v * (p / total) for v, p in zip(values, probabilities))}
at = [(key, level(q) if level else q) for key, q in (("p10", 0.1), ("median", 0.5), ("p90", 0.9))]
mass = 0.0
for value, p in zip(values, probabilities):
mass += p / total
for key, quantile in at:
if key not in out and mass >= quantile:
out[key] = value
for key, _ in at: # a level near 1 the summed mass falls short of by rounding: the last value
out.setdefault(key, values[-1])
return out