﻿# BentoML model declarations: local constructor loading can hide a missing deployment dependency

Declare BentoModel and HuggingFaceModel dependencies at BentoML Service class scope so build-time discovery matches the model artifacts needed during startup.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-bentoml-class-model-dependency-build-discovery/
Language: en

## The model exists only in the developer's store

A developer loads a model from a local store inside a Service constructor. Local inference succeeds, but the transported Bento cannot find the model in its clean environment. The constructor demonstrated that the local machine had usable data. It did not necessarily declare the model dependency in the form the build process discovers.

Separate identifying the dependency from initializing the runtime object. Both are necessary, but they happen at different boundaries and should be reviewed independently when a service moves from a workstation to deployment.

## Class-scope references declare dependencies

The [BentoML model management guide](https://docs.bentoml.com/en/latest/build-with-bentoml/model-loading-and-management.html) documents class-level BentoModel and HuggingFaceModel references. It explicitly distinguishes this declaration from creating those references only inside the constructor, where build discovery can miss them.

Keep runtime deserialization in the intended instance lifecycle while exposing the dependency through the supported declaration. A declaration can identify the artifact, whereas framework loading establishes the actual model object that will process requests.

## Packaged models and remote downloads differ

The guide also distinguishes Model Store dependencies packaged into a Bento from Hugging Face references recorded with a pinned revision and downloaded at service startup. These approaches have different startup availability requirements even when they ultimately produce a model directory for the framework.

Record the resolved model identity and its retrieval path. An [artifact release manifest](/journal/tokenizer-artifact-release-manifest/) connects weights, tokenizer and configuration. A successful build is not proof that every startup environment can retrieve every required remote object.

## Inspect the deployment package deliberately

The [packaging guide](https://docs.bentoml.com/en/latest/get-started/packaging-for-deployment.html) describes Bentos as packages of service code, dependencies and configuration. The [store API reference](https://docs.bentoml.com/en/latest/reference/bentoml/stores.html) documents model and Bento management. Use those boundaries to distinguish the model in a developer's store from the dependency carried by a specific built version.

Validate startup in a clean environment with the intended artifact access. This reveals reliance on undeclared local files or caches that can make development appear more portable than it actually is.

## Test loading and inference separately

Confirm the dependency resolves, the framework loads it and a small representative request returns the expected output structure. These observations establish progressively stronger properties instead of equating package existence with working inference.

[Artifact signature verification](/journal/artifact-signature-verification/) adds identity evidence where applicable. Dependency discovery, retrieval, authenticity and runtime compatibility complement one another; none should be inferred solely from a successful constructor on the original workstation.
