Skip to content

feat: support auto-resolved template model IDs#216

Open
xichengpro wants to merge 2 commits into
modelscope:mainfrom
xichengpro:main
Open

feat: support auto-resolved template model IDs#216
xichengpro wants to merge 2 commits into
modelscope:mainfrom
xichengpro:main

Conversation

@xichengpro
Copy link
Copy Markdown
Contributor

@xichengpro xichengpro commented Jun 3, 2026

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

Write the detail information belongs to this PR.

  • add template_init_model_id to SupportedModel to support configuring the target model ID used for template initialization
  • add the template_model_id helper module, preferring an explicit model ID and otherwise resolving it from server capabilities
  • update MultiLoraTransformersModel.set_template and vLLMSampler.set_template to replace model ID passing with the new resolution flow

Experiment results

Paste your experiment result here(if needed).

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a mechanism to resolve template model IDs dynamically by querying server capabilities. It adds a utility function resolve_template_model_id and integrates it into client template setup methods, while also updating the server launcher to merge configured supported models with those derived from application configs. Feedback highlights a bug where self.model_id retains the twinkle:// prefix in MultiLoraTransformersModel, and suggests improvements such as using model_dump() or dict() for Pydantic model normalization, calling raise_for_status() before parsing JSON responses, and adding exception handling to gracefully handle unreachable servers.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread client_tools/client_generator.py
Comment on lines +57 to +65
if hasattr(item, 'model_name'):
model_name = getattr(item, 'model_name', None)
if not model_name:
return None
template_init_model_id = getattr(item, 'template_init_model_id', None)
return {
'model_name': model_name,
'template_init_model_id': template_init_model_id,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When normalizing a supported model item, if the item is a Pydantic model (which has the model_name attribute), extracting only model_name and template_init_model_id will silently drop any other fields that might be present on the model. To ensure extensibility and preserve all fields, we should check if the item has a model_dump or dict method and use that to serialize it to a dictionary.

Suggested change
if hasattr(item, 'model_name'):
model_name = getattr(item, 'model_name', None)
if not model_name:
return None
template_init_model_id = getattr(item, 'template_init_model_id', None)
return {
'model_name': model_name,
'template_init_model_id': template_init_model_id,
}
if hasattr(item, 'model_name'):
if hasattr(item, 'model_dump'):
return item.model_dump()
if hasattr(item, 'dict'):
return item.dict()
model_name = getattr(item, 'model_name', None)
if not model_name:
return None
template_init_model_id = getattr(item, 'template_init_model_id', None)
return {
'model_name': model_name,
'template_init_model_id': template_init_model_id,
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks.

Comment on lines +14 to +15
response = http_get(f'{base_url}/twinkle/get_server_capabilities')
_SERVER_CAPABILITIES_CACHE[base_url] = GetServerCapabilitiesResponse(**response.json())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The HTTP response from http_get is parsed directly via response.json() without calling response.raise_for_status(). If the request fails (e.g., due to a 404 or 500 error), this can lead to unhelpful or cryptic errors (like JSONDecodeError or ValidationError). Calling raise_for_status() first ensures that HTTP errors are surfaced clearly.

Suggested change
response = http_get(f'{base_url}/twinkle/get_server_capabilities')
_SERVER_CAPABILITIES_CACHE[base_url] = GetServerCapabilitiesResponse(**response.json())
response = http_get(f'{base_url}/twinkle/get_server_capabilities')
response.raise_for_status()
_SERVER_CAPABILITIES_CACHE[base_url] = GetServerCapabilitiesResponse(**response.json())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks.

Comment on lines +31 to +33
supported_model = get_supported_model_by_name(model_name)
if supported_model and supported_model.template_init_model_id:
return supported_model.template_init_model_id
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the server is temporarily unreachable or running an older version that does not support the /twinkle/get_server_capabilities endpoint, get_supported_model_by_name will raise an exception and crash the client's set_template call. Wrapping this in a try-except block ensures defensive programming and allows the client to gracefully fall back to using model_name directly.

Suggested change
supported_model = get_supported_model_by_name(model_name)
if supported_model and supported_model.template_init_model_id:
return supported_model.template_init_model_id
try:
supported_model = get_supported_model_by_name(model_name)
if supported_model and supported_model.template_init_model_id:
return supported_model.template_init_model_id
except Exception:
pass

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks.

@Yunnglin
Copy link
Copy Markdown
Collaborator

Yunnglin commented Jun 3, 2026

Hi @xichengpro,

Thanks — the capability-declaration flow is a nice cleanup, and the self.model_id ordering fix in __init__ is a real latent bug catch.

Heads up: #210 is a parallel server-config refactor that reshapes the launcher (_deploy_application now takes a typed ApplicationSpec, self.config becomes ServerConfig). The refactor already predeclared ServerArgs.supported_models, so the data shape lines up.

Since the launcher helpers here would need to be rewritten against the typed config, we'll fold the intent into #210 directly with Co-authored-by: attribution, and close this PR once #210 merges. Flagging here first so it's not a surprise.

Yunnglin added a commit that referenced this pull request Jun 5, 2026
Sampler's set_template now auto-injects self.model_id when the caller
omits it, consistent with how the model backend already overrides
model_id with self.tokenizer_id. This eliminates the need for clients
to manually resolve the HF model ID when the route name differs from
the underlying model.

Also fixes two client-generator bugs: model client assigned self.model_id
before stripping the twinkle:// prefix, and sampler client was missing
self.model_id entirely.

Co-authored-by: xichengpro <188454548+xichengpro@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants