Run this model with HF Jobs

Run yuhuanstudio/Yunmo-Next-1B-Base 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/yuhuanstudio/Yunmo-Next-1B-Base. 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/yuhuanstudio/Yunmo-Next-1B-Base 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/yuhuanstudio/Yunmo-Next-1B-Base. 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/yuhuanstudio/Yunmo-Next-1B-Base. 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.
yuhuanowo's picture
Initial private upload for owner review
a9698d2 verified
Raw History Blame Contribute Delete
2.95 kB
from __future__ import annotations
import torch
def validate_cu_seqlens(cu_seqlens: torch.Tensor, sequence_length: int) -> None:
if cu_seqlens.ndim != 1 or cu_seqlens.numel() < 2:
raise ValueError("cu_seqlens must contain at least one start/end pair")
if cu_seqlens.dtype != torch.long:
raise ValueError("cu_seqlens must use torch.long")
if int(cu_seqlens[0]) != 0 or int(cu_seqlens[-1]) != sequence_length:
raise ValueError("cu_seqlens must span the complete flattened sequence")
if not bool(torch.all(cu_seqlens[1:] > cu_seqlens[:-1])):
raise ValueError("cu_seqlens must be strictly increasing")
def document_starts(
cu_seqlens: torch.Tensor, sequence_length: int
) -> torch.Tensor:
validate_cu_seqlens(cu_seqlens, sequence_length)
starts = torch.zeros(sequence_length, dtype=torch.bool, device=cu_seqlens.device)
starts[cu_seqlens[:-1]] = True
return starts.unsqueeze(0)
def document_position_ids(
cu_seqlens: torch.Tensor, sequence_length: int
) -> torch.Tensor:
validate_cu_seqlens(cu_seqlens, sequence_length)
lengths = cu_seqlens[1:] - cu_seqlens[:-1]
offsets = torch.repeat_interleave(cu_seqlens[:-1], lengths)
return (torch.arange(sequence_length, device=cu_seqlens.device) - offsets).unsqueeze(0)
def document_causal_mask(
cu_seqlens: torch.Tensor,
sequence_length: int,
*,
window: int | None = None,
) -> torch.Tensor:
validate_cu_seqlens(cu_seqlens, sequence_length)
identifiers = document_identifiers(cu_seqlens, sequence_length)
positions = torch.arange(sequence_length, device=cu_seqlens.device)
distance = positions[:, None] - positions[None, :]
mask = (identifiers[:, None] == identifiers[None, :]) & (distance >= 0)
if window is not None:
if window <= 0:
raise ValueError("attention window must be positive")
mask &= distance < window
return mask
def document_identifiers(
cu_seqlens: torch.Tensor, sequence_length: int
) -> torch.Tensor:
validate_cu_seqlens(cu_seqlens, sequence_length)
lengths = cu_seqlens[1:] - cu_seqlens[:-1]
return torch.repeat_interleave(
torch.arange(lengths.numel(), device=cu_seqlens.device), lengths
)
def segment_ranges(cu_seqlens: torch.Tensor, sequence_length: int) -> list[tuple[int, int]]:
validate_cu_seqlens(cu_seqlens, sequence_length)
boundaries = cu_seqlens.detach().cpu().tolist()
return list(zip(boundaries[:-1], boundaries[1:], strict=True))
def mask_cross_document_labels(
labels: torch.Tensor, cu_seqlens: torch.Tensor, *, ignore_index: int = -100
) -> torch.Tensor:
if labels.ndim != 2 or labels.shape[0] != 1:
raise ValueError("packed labels must have shape [1, sequence]")
validate_cu_seqlens(cu_seqlens, labels.shape[1])
result = labels.clone()
boundaries = cu_seqlens[1:-1] - 1
result[0, boundaries] = ignore_index
return result