Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions lib/llm/src/local_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ impl LocalModelBuilder {
migration_limit: self.migration_limit,
migration_max_seq_len: self.migration_max_seq_len,
self_host_metadata: self.self_host_metadata,
attached_self_host_suffix: None,
});
}

Expand Down Expand Up @@ -353,7 +352,6 @@ impl LocalModelBuilder {
migration_limit: self.migration_limit,
migration_max_seq_len: self.migration_max_seq_len,
self_host_metadata: self.self_host_metadata,
attached_self_host_suffix: None,
})
}
}
Expand All @@ -376,9 +374,6 @@ pub struct LocalModel {
migration_limit: u32,
migration_max_seq_len: Option<u32>,
self_host_metadata: bool,
/// Set by `move_to_self_host` so `clear_self_hosted_artifacts`
/// scopes its unregister to this model's `(slug, suffix)` only.
attached_self_host_suffix: Option<String>,
}

impl LocalModel {
Expand Down Expand Up @@ -512,7 +507,7 @@ impl LocalModel {
);

if self.self_host_metadata {
self.move_to_self_host(endpoint.drt(), model_suffix.as_deref())
self.move_to_self_host(endpoint, model_suffix.as_deref())
.context("move_to_self_host")?;
}

Expand Down Expand Up @@ -555,9 +550,13 @@ impl LocalModel {
/// (recorded as `BASE_SUFFIX` in the registry).
fn move_to_self_host(
&mut self,
drt: &dynamo_runtime::DistributedRuntime,
endpoint: &Endpoint,
model_suffix: Option<&str>,
) -> anyhow::Result<()> {
let drt = endpoint.drt();
let namespace = endpoint.component().namespace().name().to_string();
let component = endpoint.component().name().to_string();
let endpoint_name = endpoint.name().to_string();
let Some(base_url) = self_host_base_url(drt)? else {
tracing::warn!(
model_slug = %self.card.slug(),
Expand All @@ -570,6 +569,8 @@ impl LocalModel {
let model_slug = self.card.slug().to_string();
let suffix = model_suffix.unwrap_or(dynamo_runtime::metadata_registry::BASE_SUFFIX);
let registry = drt.metadata_artifacts();
let instance_id = drt.connection_id();
let owner = (instance_id, model_suffix.map(str::to_string));

// Advertise non-typed siblings (preprocessor_config.json,
// special_tokens_map.json, …) so external preprocessors that load
Expand Down Expand Up @@ -619,14 +620,24 @@ impl LocalModel {
};

let url = url::Url::parse(&format!(
"{base_url}/v1/metadata/{model_slug}/{suffix}/{filename}"
"{base_url}/v1/metadata/{namespace}/{component}/{endpoint_name}/{model_slug}/{suffix}/{filename}"
))?;
registry.register(&model_slug, suffix, &filename, absolute);
registry
.register(
&owner,
&namespace,
&component,
&endpoint_name,
&model_slug,
suffix,
&filename,
absolute,
)
.context("registering metadata artifact")?;
cf.move_to_url(url);
rewritten += 1;
}

self.attached_self_host_suffix = Some(suffix.to_string());
tracing::debug!(
model_slug,
suffix,
Expand All @@ -637,15 +648,6 @@ impl LocalModel {
Ok(())
}

/// Idempotent. Call before detach/hot-reload; otherwise the
/// runtime drops the registry entries with the worker process.
pub fn clear_self_hosted_artifacts(&self, drt: &dynamo_runtime::DistributedRuntime) {
if let Some(suffix) = self.attached_self_host_suffix.as_deref() {
drt.metadata_artifacts()
.unregister(self.card.slug().as_ref(), suffix);
}
}

/// Helper associated function to detach a model from an endpoint
///
/// For base models, pass `lora_name = None`.
Expand All @@ -658,8 +660,8 @@ impl LocalModel {
let instance_id = drt.connection_id();
let endpoint_id = endpoint.id();

// Compute model_suffix from lora_name if present
let model_suffix = lora_name.map(|name| Slug::slugify(name).to_string());
let registry_owner = (instance_id, model_suffix.clone());

let instance = DiscoveryInstance::Model {
namespace: endpoint_id.namespace,
Expand All @@ -672,6 +674,8 @@ impl LocalModel {

let discovery = drt.discovery();
discovery.unregister(instance).await?;
drt.metadata_artifacts()
.unregister_for_owner(&registry_owner);

if let Some(lora_name) = lora_name {
tracing::info!(
Expand Down
Loading
Loading