Skip to content

feat: rank model-id suggestions by downloads and suggest on the not-found path#66

Open
AhmedDlshad007 wants to merge 2 commits into
kubeflow:mainfrom
AhmedDlshad007:feat/hf-suggestions-not-found-and-ranking
Open

feat: rank model-id suggestions by downloads and suggest on the not-found path#66
AhmedDlshad007 wants to merge 2 commits into
kubeflow:mainfrom
AhmedDlshad007:feat/hf-suggestions-not-found-and-ranking

Conversation

@AhmedDlshad007

Copy link
Copy Markdown
Contributor

Description

Follow-up to #43 (fix for #40), implementing the two enhancements from #65. Both improve the HuggingFace model-id suggestions that pre_flight / estimate_resources return for a bad model id.

Type of Change

  • feat: New feature
  • fix: Bug fix
  • revert: Revert a change
  • chore: Maintenance / tooling

Checklist

  • Tests pass locally (184 passing)
  • Linting passes (ruff check + ruff format + pre-commit, under both ruff 0.14.14 and 0.15.x)
  • Documentation updated (if applicable)
  • Commit messages follow conventional format

Related Issues

Fixes #65

Changes

  1. Rank suggestions by downloads. _suggest_hf_model_ids now passes sort="downloads" to list_models, so canonical repos surface ahead of community fine-tunes.
  2. Suggest on the not-found path too. A valid-format but nonexistent id (a typo like meta-lama/Llama-3) previously hit the except branch in _get_model_info_from_hf and returned only the raw Hub error. It now reuses _suggest_hf_model_ids. Since a typo in the org makes the full org/name search come back empty, the helper retries on just the model name so the user still gets a "did you mean".

Verified end to end (live Hub)

estimate_resources("qwen3:8b")           # format branch, ranked
  -> ['Qwen/Qwen3-0.6B', 'Qwen/Qwen3-8B', 'Qwen/Qwen3-Embedding-0.6B']   (was community fine-tunes)

estimate_resources("meta-lama/Llama-3")  # not-found path, org typo -> name fallback
  -> ['meta-llama/Llama-3.2-1B-Instruct', 'meta-llama/Llama-3.1-8B-Instruct', 'meta-llama/Llama-3.2-3B-Instruct']

Tests Added

Five new tests in test_planning.py (mocking list_models / model_info): download ranking, the org-typo name fallback, not-found suggestions at both the helper and the estimate_resources boundary, and graceful omission when the Hub errors.

…ound path

Two follow-ups to the HuggingFace model-id suggestions from kubeflow#43:

- Rank suggestions by downloads (list_models sort="downloads") so canonical
  repos surface ahead of community fine-tunes (e.g. qwen3:8b now suggests
  Qwen/Qwen3-8B rather than community forks).
- Also suggest on the not-found path: a valid-format but nonexistent id
  (e.g. a typo like meta-lama/Llama-3) previously returned only the raw Hub
  error. It now reuses _suggest_hf_model_ids, and when a typo'd org makes the
  full "org/name" search empty, it retries on just the model name so the user
  still gets a "did you mean" list.

Covered by unit tests (mocking list_models/model_info) and verified end to
end against the live Hub.

Fixes kubeflow#65

Signed-off-by: Ahmed <ahmed.dlshad.m@gmail.com>
Copilot AI review requested due to automatic review settings July 12, 2026 14:29
@google-oss-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign abhijeet-dhumal for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copilot AI left a comment

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.

Pull request overview

Improves Hugging Face model-ID suggestions for invalid or nonexistent models.

Changes:

  • Ranks suggestions by downloads.
  • Retries searches without the organization name.
  • Surfaces suggestions when model lookup fails.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
kubeflow_mcp/trainer/api/planning.py Implements ranking, fallback searches, and error-path suggestions.
tests/unit/trainer/test_planning.py Tests the new suggestion behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread kubeflow_mcp/trainer/api/planning.py Outdated
Comment on lines +97 to +102
except Exception as e:
return {"error": str(e)}
# A valid-format but nonexistent id (e.g. a typo) lands here rather than
# the format branch above; offer the same best-effort suggestions so
# callers still get a "did you mean" list.
result: dict[str, Any] = {"error": str(e)}
suggestions = _suggest_hf_model_ids(model)

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.

Narrowed the suggestion lookup to huggingface_hub RepositoryNotFoundError, so timeouts, rate-limits, and metadata errors now surface unchanged with no extra Hub request. Confirmed that gated repos (Llama/Gemma) return metadata from model_info without raising, so they never reach this branch. Added a test asserting a non-not-found error (a timeout) attaches no suggestions and makes no list_models call.

…rors

Address review feedback. The not-found suggestion lookup ran in a broad
except that caught every model_info failure, so a timeout, rate-limit, or
metadata error would make an extra Hub request and could attach misleading
"did you mean" results. Narrow it to huggingface_hub RepositoryNotFoundError;
gated repos return metadata fine and never reach here, and all other errors
are surfaced unchanged with no extra Hub call.

Signed-off-by: Ahmed <ahmed.dlshad.m@gmail.com>
@google-oss-prow google-oss-prow Bot added size/L and removed size/M labels Jul 12, 2026
@abhijeet-dhumal

Copy link
Copy Markdown
Member

/ok-to-test

@google-oss-prow google-oss-prow Bot added the ok-to-test Approve CI for external contributors label Jul 18, 2026

@abhijeet-dhumal abhijeet-dhumal Jul 18, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: This file has some pre-existing comments still saying suggestions come from the format check. They also attach on RepositoryNotFoundError now .. maybe worth a one-line update. WDYT?

if not normalized:
return []
terms = [normalized]
name = normalized.rsplit("/", 1)[-1]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit only: when the org typo path falls back to just the model name (e.g. "Llama-3"), Hub search can be broad.
limit=3 + sort=downloads can keep it usable.. wdyt?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Btw optionally we can skip the name-only retry when len(name) is very short.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Approve CI for external contributors size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Follow-ups from #43: suggest on the not-found path, and prefer canonical repos in ranking

3 participants