Repository navigation
feat(adapters)!: prompt fallback for adapter functions without a trained adapter - #1654
Conversation
…ned adapter
When no aLoRA or LoRA adapter exists for a capability on the target model,
resolution falls back to a hand-authored prompt (an io.yaml instruction) run
against the plain base model instead of failing. resolve_adapter probes
aLoRA -> LoRA -> model-specific prompt -> model-agnostic "any" prompt (warning
on "any") and registers the first that exists. Implemented for LocalHFBackend.
- PromptBinding: weightless WeightsBinding (no-op verbs; activate() logs) plus
AdapterType.PROMPT; Identity accepts "prompt".
- resolve_adapter is availability-aware, replacing the hardcoded LoRA
registration; it now selects aLoRA where one exists on the LocalFile path,
which the hardcoded path never reached.
- Weightless HF generate path runs against the base model with no adapter_scope.
- util: adapter_subpath/obtain_io_yaml take adapter_type (str, was alora: bool);
new resolve_prompt_io_yaml.
- Add AdapterNotFoundError (a ValueError subclass) for the not-found signal, so
the fallback walk advances only on a genuine miss and other ValueErrors
(e.g. HFValidationError) propagate rather than being masked.
- Generalize the invocation-complete telemetry helpers to carry binding_type
and revision (was embedded-only); OpenAI's embedded path migrated onto them.
- Tests and docs for the prompt fallback.
BREAKING CHANGE: obtain_lora and obtain_io_yaml (public, exported from
mellea.formatters.granite.intrinsics) replace the `alora: bool` parameter with
`adapter_type: str` ("lora" | "alora" | "prompt"). Keyword callers passing
alora=True must switch to adapter_type="alora"; positional callers must account
for the removed parameter.
Assisted-by: Claude Code
Signed-off-by: Alex Bozarth <[email protected]>
There was a problem hiding this comment.
Reviewed at 4643f67. Thanks for this, and particularly for the "behaviour change worth a close look" paragraph. It sent me to measure the aLoRA selection change on a real model, and that turned out to be the most consequential thing here.
The design holds up. All five decisions from #993's 2026-09-03 meeting are implemented as agreed, including the subtle one: AdapterNotFoundError makes the fallback a genuine not-found mechanism, so a Hub auth or validation error still propagates. The walk is 92% covered with every rung exercised, and PromptBinding is at 100%.
Four asks, each on the line it concerns:
huggingface.py:1244an explicitadapter_typesno longer has any effect on this backend.adapter.py:539preferring aLoRA regresses requirement checking today. The ask is small: keep today's rung order and link the issues. The gate belongs in #1678.adapter.py:588a promptio.yamlwith noinstructionreturns a fabricated score.huggingface.py:3017and:1408the branches that make the feature work are not executed by any test. They do work, I ran them, so this is test debt.
Issues opened from this review: #1678 aLoRA activation is unverifiable, #1679 the published requirement-check aLoRA, #1680 result-level provenance, #1681 a coverage rule that hides these generation helpers from measurement.
Documentation points that have no line to sit on
- The title carries
!, but the body never lists what breaks. As far as I can tell: the three path-helper signatures losingalora, theIdentity.adapter_typewidening for exhaustive consumers, and whatever validation-mechanism change survives ask 2. - Sibling docs the new binding did not reach:
metrics.py:1236,docs/docs/observability/metrics.md:317, the module list at_core.py:10-18, the staleLiteral["lora", "alora"]atadapter.py:314, and theconfig=contract atadapter.py:674-681andhuggingface.py:2889-2896, which still says config is rejected for every shape other than Embedded while the code now accepts it for Prompt. The "composed Embedded adapter" wording inlist_adaptersandremove_adaptercovers Prompt too now. - Two sentences would help the next reader: why probing the pinned revision beats the catalogue for availability, given the epic's removed TODO said selection would come from the catalogue; and that prompt fallback is LocalHF-only today.
- The e2e test's
TODOcould cite #1655, so the stopgap is traceable from the code.
Things I checked that came back clean
Registry symmetry, so a prompt adapter can be listed and removed like the others. Lock ordering in the new registration branch, which keeps resolve then activation and does its fetch outside the activation lock. Enum widening, where every AdapterType consumer either asserts the two trained types or reads the catalogue. The Ollama signature port. Exports and __all__ in both packages. And the obvious worry from #1634, that RAG documents might be dropped on a new path: they cannot be, because the weightless path reuses the same rewriter output and the same generate_input.
Also #1655 already covers the private e2e fixture repository with acceptance criteria, which is more than most stopgaps get.
planetf1
left a comment
There was a problem hiding this comment.
Follow-up to my earlier review, from re-running the measurement behind "preferring aLoRA regresses requirement checking today". The premise has changed; see the updated #1679 and #1685.
- The aLoRA was never activated on this backend at all: adapters load through the bare
model.load_adapter()path, so PEFT's aLoRA offset computation (which only runs inside thePeftModelwrapper) never executed. Zero hook calls, measured. That bug is fixed in #1685. - The weights are not broken: the
uncertaintyaLoRA works as-published once activation is fixed, and the requirement-check items previously attributed to the weights answer correctly under activation. - The requirement-check io.yaml tokenization mismatch is real; the durable fix is a granitelib republish, and #1685 carries a removable repair in the meantime.
What this means: aLoRA is broken on main today, and that is exactly why this PR's switch to preferring aLoRA was a problem when I reviewed it. If #1685 merges first, that switch becomes an improvement instead, and I'll take back that part of my review. #1678 (aLoRA silently never activating) is fixed by #1685, so it can close with it. My other points in the review are unchanged.
jakelorocco
left a comment
There was a problem hiding this comment.
I agree with Nigel's comments. I deleted my duplicate comments that raised the same issues.
| binding_type: str, | ||
| revision: str | None = None, |
There was a problem hiding this comment.
Is there a reason to not just pass the WeightsBinding object here instead of its sub-pieces? Similar to how the actual Identity object is getting passed in as well?
… check Assisted-by: Claude Code Signed-off-by: Alex Bozarth <[email protected]>
|
Leaving a note here as this has sat seemly untouched for a while: I am actively working through the above review and hope to push an update, respond to comments, and open follow up issue soon (maybe tomorrow hopefully no later than Monday) |
…or prompt fallback Harden prompt-fallback resolution: validate the io.yaml at resolve time (via make_config_dict, requiring a non-empty instruction) and honor the catalogue's adapter_types in the walk. Make PromptBinding's type structural, the path helpers' kwargs keyword-only, and pass the weights binding to telemetry rather than unpacked fields. Soften the terminal miss message so it doesn't claim a repo is missing an adapter when the cache is just offline. Add seam/narrowing unit coverage and document the fallback's quality, provenance, and implicit-registration routing in the adapter docs. Assisted-by: Claude Code Signed-off-by: Alex Bozarth <[email protected]>
|
@planetf1 @markstur @jakelorocco thank you for the review, I have finally finished rebasing on latest main and addressing all your feedback. Everything should be covered in f740378 or by one of the three follow up issues I have opened to continue this work after this PR merges:
If you could please re-review to make sure we've caught everything. Also worth noting now that #1748 is open for followup this PR is "finalized" for review |
|
@planetf1 @markstur @jakelorocco soft ping for re-review |
planetf1
left a comment
There was a problem hiding this comment.
Overall this looks good, apart from the inline comments.
make_config_dict's return type is now `dict`, not `dict | None`: it always raised rather than returning None, so callers no longer need a None guard. Assisted-by: Claude Code Signed-off-by: Alex Bozarth <[email protected]>
Assisted-by: Claude Code Signed-off-by: Alex Bozarth <[email protected]>
planetf1
left a comment
There was a problem hiding this comment.
@ajbozarth All looks good here. thanks for that last batch of updates. I was also able to check running end to end
a3d8e82
Pull Request
Issue
Fixes #993
(Indirectly) Fixes #1627
Description
Adds prompt-based fallbacks for Granite adapter functions on the LocalHF backend. When no trained aLoRA or LoRA adapter exists for a capability on the target model, resolution now falls back to a hand-authored prompt (packaged as an
io.yamlinstruction) run against the plain base model instead of failing — the only mechanism available for models a LoRA cannot be loaded into.resolve_adapterwalks the chain per capability + base model and registers the first rung that exists: model-specific aLoRA → model-specific LoRA → model-specific prompt → model-agnosticanyprompt (with a warning on theanyrung, since it is less accurate than a model-tuned one).What's included:
PromptBinding— a weightlessWeightsBinding(no-opprepare/deactivate/release;activate()only logs), plusAdapterType.PROMPTand a widenedIdentity.adapter_type.resolve_adapter(_register_available_composed_adapter) that probes the chain via a tinyio.yamlfetch, replacing the previous hardcoded LoRA registration._generate_composed_prompt) that runs the intrinsic's injected instruction against the base model with noadapter_scope._afire_invocation_complete/_await_generation_reporting_error) that now carriesbinding_typeandrevision; the OpenAI embedded path is migrated onto the shared helpers.anymodel slot (adapter_subpath/obtain_io_yamlnow take anadapter_typestring; newresolve_prompt_io_yaml).AdapterNotFoundError(aValueErrorsubclass) for the not-found signalobtain_loraraises, so the resolution walk andresolve_prompt_io_yamladvance only on a genuine miss and let otherValueErrors (e.g. a Hugging FaceHFValidationError) propagate instead of being masked as "not found".docs/docs/advanced/intrinsics.md) and the binding-shape references.Behavior change worth a close look: because resolution is now availability-aware, it selects an aLoRA adapter where one exists on the LocalFile path — previously that path hardcoded LoRA, so an aLoRA was never auto-selected there. This closes a gap documented against Epic #929 "Phase 2", which has no discrete tracked issue of its own. The aLoRA-via-LocalFile path was not previously exercised in production, so it is worth confirming it loads and generates as expected.
Deferred to a follow-up PR: OpenAI and Ollama prompt fallback. Ollama landed as a third adapter backend on
mainwhile this work was in progress, so the follow-up will design the served-adapter prompt fallback uniformly across OpenAI and Ollama in the resolution layer (registering aPromptBindingso the high-level intrinsic helpers reach it) rather than per-backend. This PR is LocalHF-only and self-contained; the weights-binding support table reflects that (LocalHF ✅, OpenAI / Ollama —).Note on the e2e tests: the end-to-end resolution tests target a temporary private repo (
ajbozarth/granitelib-rag-r1.0, a weights-stripped copy ofibm-granite/granitelib-rag-r1.0with promptio.yamlfiles added). Because that repo is private, the testsxfail(rather than hard-fail) wherever it is not readable with the current token — including CI's public-only token and any other developer's token — and run normally for a developer with access. They should be retargeted to a public repo once one carries this layout (marked with a TODO in the test), at which point the access guard goes inert.Testing
New unit tests (no network): prompt-subpath / path-helper resolution,
PromptBindingverbs +AdapterType.PROMPT, the availability walk across every rung (trained hit, LoRA fallthrough, model-specific prompt,anyprompt + warning, hard-error abort, terminal not-found), and the weightless HF generate path. New e2e tests exercise the resolution chain — including an aLoRA-preference and a LoRA-only case — against the test repo. Ran the adapter / HF / OpenAI / Ollama / formatter unit + integration subsets locally after rebasing onmain; the full suite runs in CI.Attribution
Adding a new component, requirement, sampling strategy, or tool?
If your PR adds or modifies one of the types below, check the matching box. A checklist of type-specific review items will be posted as a comment.
NOTE: Please ensure you have an issue that has been acknowledged by a core contributor and routed you to open a pull request against this repository. Otherwise, please open an issue before continuing with this pull request.