PretrainedSource

Models & Types · AiDotNet.ModelLoading.Pretrained

A declarative description of where a pretrained model comes from and how to decode it. Hand one to AiModelBuilder.ConfigureModel(...) and the builder resolves it to a ready-to-use model — no loader classes to wire up yourself.

For Beginners

This is just a small “recipe card” that says which model to load and in what precision. It does not do any loading by itself — the builder reads the card and does the work.

How It Works

Create one with a factory method and (optionally) refine it fluently:

Properties

Property Summary
PretrainedDType DType { get; set; } The precision weights are decoded into.
PretrainedModelKind Kind { get; } The kind of source (Hugging Face hub id, local safetensors dir, ONNX, or GGUF).
string ArchitectureOverride { get; set; } Explicit architecture override (e.g.
string CacheDirectory { get; set; } Directory to cache downloaded hub files in.
string Locator { get; } The source locator: a Hugging Face repo id for HuggingFace, otherwise a filesystem path (directory for safetensors, file for ONNX/GGUF).
string Revision { get; set; } The hub revision (branch, tag, or commit) for HuggingFace.
string TokenizerLocator { get; set; } Optional tokenizer locator (directory path, tokenizer.json file path, or Hugging Face repo id) used when auto-attaching a tokenizer during AiModelBuilder.ConfigureModel(PretrainedSource).

Methods

Method Summary
PretrainedSource Dtype(PretrainedDType dtype) Sets the precision weights are decoded into.
PretrainedSource Gguf(string path) Creates a source pointing at a local GGUF checkpoint.
PretrainedSource HuggingFace(string repoId) Creates a source pointing at a Hugging Face Hub repository id.
PretrainedSource Onnx(string path) Creates a source pointing at a local ONNX graph, run directly through the ONNX runtime.
PretrainedSource Safetensors(string directory) Creates a source pointing at a local directory of safetensors weights + config.json.
PretrainedSource WithArchitecture(string architecture) Overrides the architecture family instead of reading it from config.json (e.g.
PretrainedSource WithCacheDirectory(string directory) Sets the directory used to cache downloaded hub files.
PretrainedSource WithRevision(string revision) Sets the hub revision (branch, tag, or commit).
PretrainedSource WithTokenizer(string locator) Explicitly specifies the tokenizer directory, tokenizer.json file, or Hugging Face Hub repository id to load alongside this pretrained model when no tokenizer was already configured on the builder.
string ToString()