Search Results for

    Show / Hide Table of Contents

    Setup, Cache, and Runtime Loading

    AI Model Hub downloads model files into the shared Hugging Face cache, turns them into Sentis models in a shared folder outside the project, and adds them to builds. Nothing is written into Assets unless you pull a model into the project.

    What Where Shared by
    Downloaded files Hugging Face cache, for example ~/.cache/huggingface/hub All Unity projects and Python tools on this machine
    Converted Sentis models AI Model Hub data folder, converted/ All Unity projects on this machine
    Setup records Library/Doji/ModelHub/imports/ This project only
    Models in a build The build's StreamingAssets, added at build time That build only

    Model files

    The file extension decides how AI Model Hub uses a file:

    Extension What AI Model Hub does Conversion settings
    .onnx Converts it to a Sentis model. Quantization and input shapes apply.
    .sentis Uses the downloaded file as it is. There is no conversion. Do not apply.
    anything else Downloads it when selected, for example a config or tokenizer file. It is not a model. —

    Selecting an .onnx file also selects its external weight files, such as model.onnx_data, model.onnx.data, or a weights.pb next to the only .onnx file of its folder, when the model has them.

    A dependency without a file list works when the model has only one format. A model with both .onnx and .sentis files needs a file list, so AI Model Hub never picks a format for you. See Manifest Schema.

    Setting up models

    A model is ready when its selected files are downloaded, its ONNX files are converted, and this project has a record of both. AI Model Hub splits that work by cost:

    Work When it runs
    Write this project's records, and reuse converted models that exist By itself: when the Editor starts, after project changes, after a download, and before Play mode.
    Download files After you confirm: the setup prompt, a Model Hub button, or the menu.
    Convert ONNX files After you confirm, because large models take CPU, memory, and time. A build or Apply & Convert counts as confirmation.

    So a model that another project on this machine already downloaded and converted with the same settings is ready without a prompt. A model needs a new conversion the first time, after its conversion settings change, and after a Sentis update that starts a new format generation. Model Hub then shows Needs conversion with the reason.

    Use the setup prompt, the action button of a model in Model Hub, the toolbar button (Download All, Convert All, or Set Up All), or Tools > Doji > AI Model Hub > Set Up All Models. The work runs as a background task with progress and Cancel, and the Editor stays usable:

    1. Find every manifest: installed packages, ProjectSettings/Packages/tools.doji.model-hub/model-hub-manifest.json, and project manifest assets.
    2. Validate them, and skip models that are ready.
    3. For models with missing files: resolve the dependency to one commit, read the model's file list at that commit, and download the selected files that are not in the cache yet. Models whose files are all cached skip this step and need no network.
    4. Convert each selected .onnx file with the Unity Inference Engine importer, unless a conversion with the same source file, format generation, and conversion settings already exists.
    5. Write the records to Library/Doji/ModelHub/imports/.

    A dependency that selects only .sentis files is Ready as soon as its files are downloaded.

    If a project declares the same model at different revisions, AI Model Hub marks each of those rows as Conflict and does not download or convert that model. Other models still sync.

    If one ONNX file of a model cannot be converted, AI Model Hub keeps the other converted files. The model is Ready, with a warning that lists the skipped files. AI Model Hub does not try again until the model, its file selection, its conversion settings, or the Inference Engine version changes. The setup fails only when no ONNX file converts.

    Download cache

    Downloaded files are stored in the Hugging Face cache, the same cache the huggingface_hub Python library uses. A model that Python tools downloaded is not downloaded again in Unity, and the other way round.

    Cache folder, in this order:

    1. a custom folder set in Preferences > Doji > AI > AI Model Hub (Editor only, per user)
    2. the HF_HUB_CACHE environment variable
    3. the hub folder inside the HF_HOME environment variable
    4. ~/.cache/huggingface/hub (on Windows %USERPROFILE%\.cache\huggingface\hub)

    Layout:

    models--<owner>--<name>/refs/<revision>
    models--<owner>--<name>/blobs/<etag>
    models--<owner>--<name>/snapshots/<commit>/<repo-file>
    

    File content is stored once in blobs/. Each snapshot file is a link to its blob. Where the file system does not allow symbolic links (Windows without Developer Mode), snapshot files are copies, as in the Python library.

    AI Model Hub data folder

    AI Model Hub keeps its own files outside the Hugging Face cache, so Python tools never see them:

    Platform Folder
    Windows %LocalAppData%\Doji\ModelHub
    macOS ~/Library/Application Support/Doji/ModelHub
    Linux ~/.cache/doji/model-hub

    It holds:

    • index/: each cached repository's file list per commit
    • converted/models--<owner>--<name>/<key>.sentis: converted Sentis models, each with a .json file that names the source file, its etag, the converter, and the conversion settings

    A converted model is found by what produced it: the source file's etag, the converter, the Inference Engine format generation, and the conversion settings. Projects with the same model and settings share one conversion.

    Most Inference Engine updates keep the .sentis format: older files are upgraded when they load. So an update reuses existing conversions. AI Model Hub converts again only when the update starts a new format generation, which AI Model Hub's own compatibility table decides. Project Settings shows the installed version and its generation.

    Remove from Project deletes this project's records. Downloaded files and converted models stay, so the model is ready again without a conversion.

    Clean up converted models

    AI Model Hub never deletes converted models on its own, because other projects on the machine may use them. Delete them from your own code with HubStorage, for example after moving every project to a new format generation:

    using Doji.AI.ModelHub;
    
    string current = HubStorage.FormatGeneration;
    int deleted = HubStorage.DeleteConvertedModels(model => model.FormatGeneration != current);
    

    HubStorage.GetConvertedModels() lists each converted model with its repository, source path, converter, format generation, size, and date. A deleted model is converted again the next time it is needed. Models that are being written are skipped. The same methods work in players, on the device's converted folder.

    Earlier versions of AI Model Hub kept downloads in a private raw folder in the data folder. On the first Editor start after an update, AI Model Hub moves those files into the Hugging Face cache without downloading them again, then deletes raw.

    Builds

    When you build a player, AI Model Hub adds each model to the build in one of two ways. The project decides, not the package.

    In builds What the build contains What the player does
    Bundle in the build (default) The Sentis model: the downloaded .sentis file, or the converted model of an .onnx file. Loads it from StreamingAssets.
    Download at runtime Only the model's entry in AI Model Hub's registry. Downloads the files from Hugging Face the first time the model loads, then loads them from the device.

    Set the default in Project Settings > Doji > AI > AI Model Hub > In builds. Override it per model in Model Hub with the In builds field.

    The build adds files to StreamingAssets directly from the shared folders. It does not copy them into Assets, so a failed build leaves nothing behind:

    StreamingAssets/model-hub/model-hub-runtime.json
    StreamingAssets/model-hub/models/<owner>/<name>/<repo-path>.sentis
    StreamingAssets/model-hub/files/<owner>/<name>/<repo-path>
    

    For example, onnx/model.onnx of onnx-community/tiny-clip-test-ONNX is bundled as model-hub/models/onnx-community/tiny-clip-test-ONNX/onnx/model.sentis.

    Selected files that are not models, such as config.json or tokenizer files, go the same way as the model: a bundled model bundles them under model-hub/files/, and a model that downloads at runtime downloads them too. A whole-repository dependency includes every such file except dotfiles such as .gitattributes. ONNX external weights are part of their model and are never added as files.

    Rules:

    • A build never contains .onnx files. An ONNX model is always bundled as its converted Sentis model, made with the conversion settings tested in the Editor.
    • Starting a build counts as confirmation: the build converts every downloaded model that needs it, with a progress bar, before it adds the models.
    • A build never downloads. It fails, with a list, when a model is not downloaded. Download it in Model Hub first. A build never ships without a model silently.
    • The registry stores the commit that the Editor resolved. Players download exactly that commit and do not ask Hugging Face for the latest revision.
    • Download at runtime for an .onnx file converts it on the device with tools.doji.onnx-model-loader.
    • Only public models can download at runtime. A build cannot contain an access token. A gated or private file fails with an IOException that names the model and file.
    • A runtime download needs the model to stay on Hugging Face at the pinned commit. A model that is deleted, or a commit removed by a force push, fails with an IOException that says so. Bundle the models whose owners you do not control.

    Pull into project

    Pull into Project in the Model Hub ⋮ menu copies a model's Sentis files into:

    Assets/StreamingAssets/model-hub/models/<owner>/<name>/
    

    Builds then use these copies instead of adding the model, and Play mode loads them. Use it to keep a model's exact file under version control. Remove Pulled Copies deletes them again. Remove from Project also deletes them, unless another manifest still uses the repository.

    Where players store models

    Player Downloaded files Converted ONNX models
    Windows, macOS, Linux The user's Hugging Face cache, shared with Python tools and the Editor The AI Model Hub data folder of that user
    Android, iOS, Web persistentDataPath/huggingface/hub persistentDataPath/model-hub/converted

    On the Web, persistentDataPath lives in the browser's IndexedDB. AI Model Hub saves it after each download and conversion, so a model downloads once per browser.

    Desktop players use the same environment variables as the Editor (HF_HUB_CACHE, HF_HOME). The custom folders in Preferences apply to the Editor only. If your application must not write to the user's Hugging Face cache, bundle its models.

    How players read bundled models:

    Platform How
    Windows, macOS, Linux, iOS Load from the file in StreamingAssets.
    Android StreamingAssets is inside the APK. The first load copies the model once to persistentDataPath/model-hub/bundled/<app-version>/, then loads the copy. Copies of earlier app versions stay until you call HubStorage.DeleteBundledCopiesOfOtherVersions(), for example once after an app update.
    Web Download the model from StreamingAssets into memory, then load it.

    Bundled models make the app larger. Google Play limits the base APK to 150 MB, and Web players download everything before they start. Set large models to Download at runtime.

    Load models at runtime

    Load a model by its model id and the file path the manifest declares. The same code works for bundled and downloaded models, in Play mode and in players:

    using Doji.AI.ModelHub;
    using Unity.InferenceEngine;
    
    Model model = await Hub.LoadModelAsync(
        "onnx-community/tiny-clip-test-ONNX",
        "onnx/model.onnx");
    

    For an .onnx path, AI Model Hub loads its converted Sentis model. A .sentis path loads the downloaded file.

    LoadModelAsync works on every platform. In download mode, the first call downloads the files and, for ONNX files, converts them. Pass a progress handler and a cancellation token to show progress:

    // DownloadProgress is in the Doji.Downloads namespace. TotalBytes is null when the size is unknown.
    var progress = new Progress<DownloadProgress>(p => Debug.Log($"{p.DownloadedBytes} / {p.TotalBytes}"));
    Model model = await Hub.LoadModelAsync(repoId, repoPath, progress, cancellationToken);
    

    Fetch every file of a model up front, for example on a loading screen:

    await Hub.EnsureAvailableAsync("onnx-community/tiny-clip-test-ONNX", progress, cancellationToken);
    

    A loader that reads several files, or files of several models, names them all in one call before it loads the first one:

    await Hub.EnsureAvailableAsync(
        HubRequest.Files("black-forest-labs/FLUX.2-klein", "transformer/model.onnx", "vae/model.onnx"),
        HubRequest.Files("Qwen/Qwen3-4B", "model.onnx", "tokenizer.json"));
    

    When the loader learns its files from the model, for example from model_index.json, use HubRequest.Select. In the Editor, for a model that the project does not list, AI Model Hub calls the function with the model's file list on Hugging Face, and the function returns the paths to use. preview.ReadTextAsync reads a small file, such as a config, without adding it to the project:

    await Hub.EnsureAvailableAsync(HubRequest.Select(modelId, async preview =>
    {
        string index = await preview.ReadTextAsync("model_index.json");
        return PickFiles(index, preview.Files);
    }));
    

    Hub.EnsureAvailable does the same for code that cannot wait. It never waits for a download.

    Load a model the project does not list

    In the Editor, outside batch mode, a load of a file that no manifest lists, or that is listed and not downloaded yet, opens the load prompt. It shows one card for each model and the size to download. Add to Project and Download adds the files to the project manifest and downloads them. A model that a package declares follows the package's version. Another model gets the version that the prompt showed, so every machine gets the same files. Choose Files… picks the files when the code named none, for example Hub.FromPretrained of a model that the project does not list.

    • An async call, such as Hub.LoadModelAsync, waits for the download and then loads.
    • A call that does not wait, such as Hub.LoadModel, opens the prompt and fails at once. Load again when the download is done.
    • Cancel fails the load. The prompt does not ask again for that model until you restart the Editor.

    See For Unity Project Users for each case of the prompt.

    In batch mode and in players there is no prompt. The error names the manifest entry to add, for example:

    { "id": "Qwen/Qwen3-4B", "files": [ { "path": "model.onnx" } ] }
    

    from_pretrained(...) style:

    PretrainedRepository repo = await Hub.FromPretrainedAsync("onnx-community/tiny-clip-test-ONNX");
    Model model = await repo.LoadModelAsync("onnx/model.onnx");
    

    repo.Files lists the model files the project uses, repo.DataFiles the other files, and repo.Commit is the commit the build uses.

    Hub.FromPretrained also takes the path of a folder on this device, like from_pretrained(path) in transformers. An existing folder wins over a model id. Its .sentis files load as models, and its other files read as data files, at their paths relative to the folder. AI Model Hub does not convert ONNX files of a folder, and no manifest needs to list it:

    PretrainedRepository local = Hub.FromPretrained("D:/models/my-model");
    

    Read configs and other files

    Read a selected file that is not a model, such as config.json or a tokenizer file, by the model id and its path in the manifest:

    string json = await Hub.ReadTextAsync("onnx-community/tiny-clip-test-ONNX", "preprocessor_config.json");
    byte[] bytes = await Hub.ReadFileAsync("onnx-community/tiny-clip-test-ONNX", "tokenizer.json");
    

    PretrainedRepository has the same ReadTextAsync and ReadFileAsync, and HasFile to check whether the project includes a path. The file must be listed in the manifest's files, or come with a whole-repository dependency. Like models, ReadText and ReadFile do not wait, and work where Hub.LoadModel works.

    A package that reads a large file itself, such as a GGUF file of llama.cpp, asks for its path instead of its bytes:

    string path = await Hub.GetFilePathAsync("ggml-org/Qwen3.5-0.8B-GGUF", "Qwen3.5-0.8B-Q8_0.gguf");
    

    The path is the cache file in the Editor, the downloaded file, or the bundled file. On Android, a bundled file is copied once out of the APK. On the Web, a bundled file is not a file, so GetFilePathAsync throws there. GetFilePath does not wait. A manifest entry may select only .gguf or .safetensors files: they count as model files for the selection, and AI Model Hub delivers them as downloaded.

    List a package's models

    Hub.GetModelFilesAsync(packageId) lists the model files of one package that the project includes, for example for a model picker. Each HubModelFile has RepoId, RepoPath, DisplayName (the manifest label, else the path), and ToReference(). Optional files the project does not use are not listed.

    A HubModelReference stores one choice, either a package's file or a ModelAsset of your own, and loads it with LoadAsync. Add [HubModel("package.id")] to a HubModelReference field to show a dropdown in the Inspector.

    Package authors get FromPretrained methods for their model class by deriving from PretrainedModel<T>, or load several models with HubModelLoader. See Design Your Package's Model API.

    Load a file of your own

    Hub.LoadModelFromFile(path) loads a model file that did not come through AI Model Hub, for example one your app downloaded:

    • A .sentis file loads as it is, with no conversion. Its weights load as the file stores them, quantized or not.
    • An .onnx file is converted with tools.doji.onnx-model-loader on every call, with float32 weights. No quantization or input shapes apply, and the converted model is not cached.

    To load an ONNX model often, or quantized, convert it once to a .sentis file. Add the model to a manifest, so AI Model Hub converts it with your conversion settings and caches the result, or call OnnxModelLoader.Save(onnxPath, sentisPath, quantization) yourself and load the .sentis file.

    Synchronous loading

    Hub.LoadModel(repoId, repoPath) and Hub.FromPretrained(repoId) do not wait. They work in the Editor, for bundled models on Windows, macOS, Linux, and iOS, and for downloaded models that are already on the device. On Android and the Web, and for models that are not downloaded yet, they throw an error that points to the async method.

    Several packages, one model

    When two packages use the same model, each sees only the files its own manifest selects. Pass the package id to load the files of one package:

    Model model = await Hub.LoadModelAsync("com.example.depth", "julienkay/sentis-MiDaS", "sentis/midas_v21_small_256.sentis");
    

    Errors

    Message starts with Cause
    AI Model Hub has no model '<repo>' No manifest declares the model, or it is not ready in this project. In a player, the build did not include it.
    AI Model Hub model '<repo>' has no file '<path>' The manifest does not select that file. The message lists the files it does select. For ReadTextAsync and ReadFileAsync, it lists the selected files that are not models.
    ... is downloaded on first use. Use Hub.LoadModelAsync A synchronous call for a model that is not on the device yet.
    In this article
    Back to top Generated by DocFX