class Modality(IntEnum) Values
TEXT | 0 | |
|---|---|---|
IMAGE | 1 | |
VIDEO | 2 | |
AUDIO | 3 |
Training is GPU-only. The configuration arrives as keyword-built structures mirroring the C ones field by field, so a field left out is zero, which the library derives:
executor = uform.Executor.for_vram(devices=[0, 1])
mesh = uform.Mesh.bootstrap(executor, uform.MeshOptions(host_domain_index=rank, host_domain_count=nodes,
directory="/shared/exchange", job="run-17"))
trainer = uform.Trainer.init_vram(executor, mesh=mesh, depth=12, hidden=512, objective=uform.Objective.JOINT,
batch=uform.BatchShape(max_rows_per_device=64, max_segments_per_device=256,
max_columns_per_row=1024, max_bags_per_device=128,
image=uform.ImageShape(patch_side=16)),
schedule=uform.Schedule(steps=100_000), seed=42)
stats = uform.TrainerStepStats()
trainer.step(modalities, contents, bags=bags, relations=uform.Relations(attract=(offsets, ids)), stats=stats)
trainer.save("checkpoint.safetensors")BatchShape nests an ImageShape, a VideoShape and an AudioShape, each also taken as a tuple of its fields in order. Masking, Contrastive, LateInteraction, Choices and Schedule configure the objectives, and Relations holds three Edges sets of buffers: size_t offsets, uint32 IDs and optional float32 weights. Contrastive and LateInteraction take a uform.PairLossForm, and trainer.step takes each item’s uform.LateInteractionSide as sides. choices, taken as text_choose takes them, and choice_targets, a float32 tape shaped as the RowsTape it answers, train the calibrated choices within the batch’s max_choices_per_item, so (probabilities, probabilities.offsets) from one model can train another.
Paths, like the mesh’s directory, cross as os.fsencode gives their bytes, while its job is a str name. trainer.step answers the pooled embeddings the loss scored when given an arena, and None otherwise. mesh.describe() answers a uform.MeshDescription, its multimem_tier a uform.MultimemTier and its gpu_class the uform.GPUClass every GPU of the run dispatches as.
ModalityWhat the bytes of one training item hold, valued as uform_modality_t.ObjectiveWhich losses a training step relaxes, valued as uform_objective_t.NegativesWhich pairs the contrastive loss pushes apart, valued as uform_negatives_t.PairLossFormHow a contrastive term turns a row of scores into forces, valued as uform_pair_loss_form_t.LateInteractionSideWhich side of a late-interaction score an item takes, valued as uform_late_interaction_side_t.ImageShapeThe image slice of a BatchShape; a zero patch_side leaves images out of the run.3class ImageShape ImageShapeImageShape(*, patch_side: int = 0, channels: int = 0) patch_sidepatch_side: Final[int] channelschannels: Final[int] VideoShapeThe video slice of a BatchShape; a zero patch_side leaves video out of the run.5class VideoShape VideoShapeVideoShape(
*,
patch_side: int = 0,
tube_frames: int = 0,
frame_stride: int = 0,
channels: int = 0,
) patch_sidepatch_side: Final[int] tube_framestube_frames: Final[int] frame_strideframe_stride: Final[int] channelschannels: Final[int] AudioShapeThe audio slice of a BatchShape; a zero chunk_samples leaves audio out of the run.3class AudioShape AudioShapeAudioShape(*, chunk_samples: int = 0, sample_rate: int = 0) chunk_sampleschunk_samples: Final[int] sample_ratesample_rate: Final[int] BatchShapeWhat one device's step carries at most, whatever the modality mix, fixed at creation.9class BatchShape BatchShapeBatchShape(
*,
max_rows_per_device: int = 0,
max_segments_per_device: int = 0,
max_columns_per_row: int = 0,
max_bags_per_device: int = 0,
max_choices_per_item: int = 0,
image: ImageShape | tuple[int, ...] | None = None,
video: VideoShape | tuple[int, ...] | None = None,
audio: AudioShape | tuple[int, ...] | None = None,
) max_rows_per_devicemax_rows_per_device: Final[int] max_segments_per_devicemax_segments_per_device: Final[int] max_columns_per_rowmax_columns_per_row: Final[int] max_bags_per_devicemax_bags_per_device: Final[int] max_choices_per_itemmax_choices_per_item: Final[int] imageimage: Final[ImageShape | None] videovideo: Final[VideoShape | None] audioaudio: Final[AudioShape | None] MaskingHow the masked objective corrupts a batch and weighs its heads; every zero derives.12class Masking MaskingMasking(
*,
token_mask_probability: float = 0.0,
token_mean_span: float = 0.0,
replace_fraction: float = 0.0,
random_fraction: float = 0.0,
image_mask_ratio: float = 0.0,
video_mask_ratio: float = 0.0,
audio_mask_ratio: float = 0.0,
text_weight: float = 0.0,
image_weight: float = 0.0,
video_weight: float = 0.0,
audio_weight: float = 0.0,
) token_mask_probabilitytoken_mask_probability: Final[float] token_mean_spantoken_mean_span: Final[float] replace_fractionreplace_fraction: Final[float] random_fractionrandom_fraction: Final[float] image_mask_ratioimage_mask_ratio: Final[float] video_mask_ratiovideo_mask_ratio: Final[float] audio_mask_ratioaudio_mask_ratio: Final[float] text_weighttext_weight: Final[float] image_weightimage_weight: Final[float] video_weightvideo_weight: Final[float] audio_weightaudio_weight: Final[float] ContrastiveHow the contrastive loss scores the pooled embeddings; every zero derives.9class Contrastive ContrastiveContrastive(
*,
matryoshka_dimensions: Sequence[int] | None = None,
temperature_groups: int = 0,
inverse_temperature: float = 0.0,
bias: float = 0.0,
negatives: Negatives = ...,
ambient_repulsion_weight: float = 0.0,
max_edges_per_device: int = 0,
pair_loss: PairLossForm = ...,
) matryoshka_dimensionsmatryoshka_dimensions: Final[Sequence[int] | None] temperature_groupstemperature_groups: Final[int] inverse_temperatureinverse_temperature: Final[float] biasbias: Final[float] negativesnegatives: Final[Negatives] ambient_repulsion_weightambient_repulsion_weight: Final[float] max_edges_per_devicemax_edges_per_device: Final[int] pair_losspair_loss: Final[PairLossForm] LateInteractionHow the late-interaction loss scores the token vectors of queries and documents; every zero derives.10class LateInteraction LateInteractionLateInteraction(
*,
weight: float = 0.0,
width: int = 0,
inverse_temperature: float = 0.0,
bias: float = 0.0,
max_query_span: int = 0,
max_query_tokens_per_device: int = 0,
max_documents_per_device: int = 0,
max_document_tokens_per_device: int = 0,
pair_loss: PairLossForm = ...,
) weightweight: Final[float] widthwidth: Final[int] inverse_temperatureinverse_temperature: Final[float] biasbias: Final[float] max_query_spanmax_query_span: Final[int] max_query_tokens_per_devicemax_query_tokens_per_device: Final[int] max_documents_per_devicemax_documents_per_device: Final[int] max_document_tokens_per_devicemax_document_tokens_per_device: Final[int] pair_losspair_loss: Final[PairLossForm] ScheduleThe learning-rate schedule: a linear warmup to the peak, then a cosine decay to the floor.5class Schedule ScheduleSchedule(
*,
learning_rate: float = 0.0,
min_learning_rate: float = 0.0,
warmup_steps: int = 0,
steps: int = 0,
) learning_ratelearning_rate: Final[float] min_learning_ratemin_learning_rate: Final[float] warmup_stepswarmup_steps: Final[int] stepssteps: Final[int] EdgesOne edge set over a step's items, as compressed sparse rows of buffers borrowed until the step is final.4class Edges EdgesEdges(
*,
offsets: Buffer | None = None,
ids: Buffer | None = None,
weights: Buffer | None = None,
) offsetsoffsets: Final[Buffer | None] idsids: Final[Buffer | None] weightsweights: Final[Buffer | None] RelationsThe contrastive targets of one step: ignored, attracted, repelled, then the run's negatives.4class Relations RelationsRelations(
*,
attract: _EdgesLike = None,
repel: _EdgesLike = None,
ignore: _EdgesLike = None,
) attractattract: Final[Edges | None] repelrepel: Final[Edges | None] ignoreignore: Final[Edges | None] TrainerStepStatsWhat step reports, overwritten by every call it is passed to, every loss its world mean.12class TrainerStepStats stepThe optimizer step the call applied, counted from one.step: int learning_rateThe learning rate it applied.learning_rate: float lossThe total loss the step minimized, its world mean.loss: float contrastive_lossThe contrastive term; 0 when absent.contrastive_loss: float masked_text_lossThe text reconstruction term, unweighted.masked_text_loss: float masked_image_lossThe image reconstruction term, unweighted.masked_image_loss: float masked_video_lossThe video reconstruction term, unweighted.masked_video_loss: float masked_audio_lossThe audio reconstruction term, unweighted.masked_audio_loss: float late_interaction_lossThe late-interaction term, weighted.late_interaction_loss: float choices_lossThe choices term over the items that made a choice, unweighted.choices_loss: float truncatedItems cut at a row's width.truncated: int droppedSegments dropped whole because the batch had no room for them, since the last stats read.dropped: int TrainerA training run on the devices of the executor it was created on, which its own verbs block on.5class Trainer init_vramBuilds one replica per device and starts or resumes the run.@classmethod
def init_vram(
executor: Executor,
/,
*,
mesh: Mesh | None = None,
resume: _PathLike | None = None,
depth: int = 0,
hidden: int = 0,
batch: BatchShape | None = None,
objective: Objective = ...,
masking: Masking | None = None,
contrastive: Contrastive | None = None,
late_interaction: LateInteraction | None = None,
choices: Choices | None = None,
schedule: Schedule | None = None,
seed: int = 0,
progress: _Progress | None = None,
progress_steps: int = 0,
) -> Trainer Calls uform_trainer_init_vram.
onA receiver whose verbs block on executor.deferredA receiver whose verbs submit to executor and answer a Deferred.stepApplies one optimizer step over this process's items and every peer's.def step(
modalities: Sequence[Modality],
contents: _Texts,
/,
*,
bags: _Words | None = None,
temperature_groups: _Words | None = None,
sides: Sequence[LateInteractionSide] | None = None,
choices: _Texts | None = None,
choice_targets: Sequence[Buffer] | _Tape | None = None,
relations: Relations | None = None,
arena: Arena | None = None,
outputs_scalar: Scalar = ...,
stats: TrainerStepStats | None = None,
) -> ArenaBuffer | None Calls uform_trainer_step.
saveWrites the weights and the step as a checkpoint.def save(
path: _PathLike,
/,
*,
progress: _Progress | None = None,
progress_steps: int = 0,
) -> None Calls uform_trainer_save.