Skip to content

m alora upload's default layout is incompatible with add-readme's generated usage code #1620

Open

Description

@planetf1

Problem

m alora add-readme always generates usage code that loads the trained
adapter via LocalFileBinding (or, before #1144, the deprecated
IntrinsicAdapter/CustomIntrinsicAdapter shims) — which only finds weights
at <name>/<base-model>/<lora|alora>/ inside the Hugging Face repo (see
adapter_subpath() in mellea/formatters/granite/intrinsics/util.py). But
m alora upload defaults to --intrinsic=False, which pushes weights flat
to the repo root instead (cli/alora/upload.py, path_in_repo=".").

A user following the CLI in the "obvious" order — train → upload →
add-readme (or add-readme → upload) — gets a broken pairing by default:
the generated README's own code fails with

ValueError: Intrinsic '<name>' as aLoRA adapter on base model '<base-model>'
not found in <repo> repository on Hugging Face Hub. Searched for path
<name>/<base-model>/alora/*

The fix already exists and works — m alora upload ... --intrinsic --io-yaml ./io.yaml pushes into the correct nested layout (upload_intrinsic() in
cli/alora/intrinsic_uploader.py) — but nothing in the CLI's own flow
surfaces that requirement until the user hits this error.

Reproducer

m alora train ./data.jsonl --base-model ibm-granite/granite-4.1-3b --output ./adapter
m alora upload ./adapter --name your-org/my-adapter   # no --intrinsic
m alora add-readme ./adapter --name your-org/my-adapter --dataset ./data.jsonl

Then run the generated INTRINSIC_README.md's own example code — it raises
the ValueError above.

Expected behavior

Some combination of:

  • add-readme detects (or is told) whether the target repo actually has the
    intrinsic-style layout, and warns/refuses if not, rather than generating
    code that's guaranteed to fail.
  • upload makes the intrinsic path harder to miss — e.g. a clearer error
    when add-readme's generated usage pattern won't work against a flat
    upload, or defaulting --intrinsic to True (a breaking CLI change,
    needs its own deprecation consideration — plain, non-intrinsic adapter
    publishing via m alora upload with no flags is also a legitimate,
    intentional use case, so this isn't a clear-cut default flip).

Filed as needs-design rather than proposing a specific fix — the right
tradeoff between the two workflows (plain PEFT publishing vs.
intrinsic/adapter-function publishing) needs discussion before implementation.

Context

Found while verifying
#1619 (part of
#1144)'s new "Adding a custom adapter function" tutorial end-to-end against
real hardware. That PR adds an explicit caveat to the tutorial and to the
CLI-generated README template pointing at --intrinsic --io-yaml as a
stopgap, but the underlying CLI ergonomics gap is unrelated to the
shim-vs-composed-Adapter change #1619 makes, and predates it — the
deprecated IntrinsicAdapter/CustomIntrinsicAdapter shims have the exact
same layout requirement, so this isn't a regression from that work.

Activity

  1. added
    p2
    needs-design
    area/alora
    area/cli
    on Sep 3, 2026
  2. added
    bug
    on Oct 6, 2026
  3. self-assigned this
    on Nov 10, 2026
  4. markstur commented on Nov 12, 2026

    @markstur
    Contributor

    Design proposal: make m alora add-readme match the repository layout (#1620)

    Status: proposal for discussion — no PR yet
    Prototype: fix/issue-1620 @ f13d382 on the fork
    Compatibility: non-breaking; no defaults flipped

    Problem

    m alora upload writes weights to the repository root unless --intrinsic --io-yaml
    is passed. That is the default and a legitimate way to publish a plain PEFT adapter.

    m alora add-readme always rendered exactly one sample: compose an Adapter with
    LocalFileBinding, which searches <name>/<base-model>/<lora|alora>/. Against a flat
    upload, the generated README's own example fails with:

    ValueError: Intrinsic '<name>' as aLoRA adapter on base model '<base-model>'
    not found in <repo> repository on Hugging Face Hub. Searched for path
    <name>/<base-model>/alora/*
    

    The problem is not that two layouts exist. It is that nothing in the CLI flow surfaces
    which layout the README is documenting, so the failure lands on whoever runs the
    generated code later.

    Goals

    • The natural order — train → upload → add-readme — produces a README whose sample
      runs, for either upload layout.
    • Plain PEFT publishing keeps working and gets a correct README.
    • No breaking CLI changes.

    Non-goals

    • Flipping upload's --intrinsic default.
    • Generating io.yaml.
    • Executing the generated sample end-to-end.
    • The adjacent template defects listed under "Deferred".

    Proposed behavior

    Resolution order

    1. Explicit --layout intrinsic or --layout flat wins; no network call.
    2. Otherwise inspect the repository once with HfApi.list_repo_files.
    3. If that cannot classify the repo — missing, README-only, no token, Hub error — ask
      which layout you intend to upload.

    Detection rule

    Every intrinsic-layout file is nested under the intrinsic name; a flat upload leaves
    weights at the root. This holds for both the current <name>/<model>/<type>/ layout and
    the older <name>/<type>/<model>/ ordering, and needs no base-model normalization.

    prefix = f"{intrinsic_name}/"
    if any(path.startswith(prefix) for path in repo_files):
        return "intrinsic"
    if "adapter_config.json" in repo_files:
        return "flat"
    return "unknown"

    State matrix

    Repository state --layout auto Generated sample
    Nested intrinsic weights detected intrinsic Adapter + LocalFileBinding + Intrinsic
    Weights at repo root detected flat AutoPeftModelForCausalLM + tokenizer
    Repo does not exist yet asks whichever the user answers
    README-only / unrecognized asks whichever the user answers
    Hub error or no token warns, then asks whichever the user answers

    What each branch documents

    Intrinsic layout (unchanged):

    weights=LocalFileBinding(
        name=_INTRINSIC_ADAPTER_NAME,
        adapter_type=AdapterType.ALORA,
        repo_id=_INTRINSIC_MODEL_ID,
        revision="main",
    )

    Flat layout (new):

    from peft import AutoPeftModelForCausalLM
    from transformers import AutoTokenizer
    
    model = AutoPeftModelForCausalLM.from_pretrained("acme/stembolts")
    tokenizer = AutoTokenizer.from_pretrained("ibm-granite/granite-4.1-3b")

    Upload warning

    A flat upload prints one warning naming the expected intrinsic path and the flags that
    produce it. The upload still succeeds; plain PEFT publishing stays supported, it just
    stops being silent about what it cannot be used for.

    CLI surface

    m alora add-readme <DATAFILE> --basemodel <model> --name <org/name> \
        [--layout auto|intrinsic|flat] ...
    
    # default: auto — detect, ask only when unknown
    # explicit: skip detection entirely
    

    Decision log

    D1 — Keep upload --intrinsic defaulting to false

    • Rejected: flip the default to --intrinsic=True.
    • Why: intrinsic upload hard-requires an io.yaml, and the CLI has no generator for
      one. Flipping the default would block anyone without an io.yaml at the upload step,
      then make them discover --no-intrinsic to get plain PEFT. It moves the failure
      earlier and adds a mandatory artifact; it does not make the workflow work.
    • Consequence: users choosing intrinsic publishing still pass the flags. Either
      choice now yields a README whose code runs, and the flat choice is no longer silent.

    D2 — Detect by default, with an explicit override

    • Rejected: a required --intrinsic flag on add-readme with no detection.
    • Why: add-readme already requires auth, network, and an LLM backend; one read-only
      listing is cheap. A flag-only design helps only users who already know the
      requirement, which is the gap the issue reports.
    • Consequence: detection is best-effort and its failure paths produce a question,
      never a hard stop. The flag remains for scripted or offline use.

    D3 — Ask when the layout is unknown

    • Rejected: refuse until the repo exists; silently assume intrinsic.
    • Why: generating the README before uploading is a documented order. Refusing breaks
      it; assuming intrinsic recreates the bug. Asking is one question in a command that
      already prompts before uploading.
    • Consequence: the unknown path is interactive. Whether auto should fail fast in a
      non-TTY is Q1.

    D4 — Render a PEFT sample for flat repos

    • Rejected: omit the integration section; refuse with remediation.
    • Why: flat publishing is a legitimate use case named in the issue. Omitting the code
      makes the README less useful; refusing leaves flat users with no README path.
    • Consequence: a second template branch to maintain and test. It is small, and its
      output is compiled by the test suite.

    D5 — Keep the token optional until upload

    • Rejected: require auth before generation.
    • Why: before this change a user could generate and inspect a README locally without
      logging in; the token was only checked after the upload confirmation. Detection should
      not remove that.
    • Consequence: with no token, auto warns that it cannot inspect the repo and asks
      for the layout. The token is still required at the upload step.

    D6 — Put the classifier in its own module

    • Rejected: inline detection in the command body.
    • Why: the rule is pure and has edge cases worth pinning — old layout, other-adapter
      prefix, intrinsic-over-root precedence. A pure function tests without Hub mocks.
    • Consequence: cli/alora/layout.py, 44 lines including docstrings.

    D7 — Keep adjacent defects out of this change

    • Deferred: the generated __main__ block hardcodes IBM_GRANITE_4_1_3B; the sample
      hardcodes AdapterType.ALORA even for LoRA training; add-readme accepts --io-yaml
      but never uses it.
    • Why: each needs its own input or decision — base-model rendering, adapter-type
      plumbing, whether io.yaml feeds generation or is removed — and bundling them makes
      the layout change harder to review.
    • Consequence: follow-up work. Q6 asks whether any should ride along.

    Open questions

    • Q1 — Non-interactive behavior. In auto mode with an unknown layout, should a
      non-TTY run fail with guidance instead of waiting for input? The existing upload
      confirmation already assumes interactivity, but CI users deserve a defined answer.
    • Q2 — Prefix check vs full path. The detector treats any file under <name>/ as
      intrinsic. Validating the full <name>/<model>/<type>/ path would be stricter but
      would reject the older layout and require base-model normalization. Is the tolerant
      prefix the right trade?
    • Q3 — Flag naming. Is --layout auto|intrinsic|flat the right surface, or should it
      be --repo-layout, or values named after the loader (peft rather than flat)?
    • Q4 — Prompt or require a flag when the repo is missing. Prompting preserves the
      add-readme-before-upload order but requires an explicit --layout when nothing can be
      detected. Which does the team prefer for scriptability?
    • Q5 — How far flat mode should depart from "intrinsic" framing. The prototype
      changes the heading to "Adapter" but keeps the template's intrinsic-oriented
      description and mellea tag. Should flat mode drop that framing entirely?
    • Q6 — Scope of follow-ups. Should the base-model and LoRA/aLoRA type hardcodes be
      one follow-up PR (they share the template's sample) and the dead --io-yaml another,
      or separate issues?

    Validation of the prototype

    Check Result
    test/cli suite 510 passed
    Layout classifier tests current layout, old layout, flat, README-only, empty, other-adapter prefix, intrinsic-over-root precedence
    Command tests explicit layout, auto-detect intrinsic/flat, unknown → prompt, invalid value
    Template tests both samples compile; flat sample contains no intrinsic loading
    Static checks ruff and mypy clean on cli/alora/
    Not covered real Hub repositories, real LLM generation, end-to-end execution of the flat sample

    Separately, the locked huggingface-hub 1.16.1 removed HfFolder, so m alora upload
    and add-readme currently fail on import with a misleading "install mellea[hf]" message.
    That is tracked as #1791 and
    is unrelated; the new tests stub the symbol so they exercise layout resolution only.

    Discussion wanted

    The prototype exists to make this concrete, not to pre-empt the decision. Nothing is
    filed upstream until the approach and Q1–Q6 are settled.

  5. markstur commented on Nov 12, 2026

    @markstur
    Contributor

    Alternatives considered (short version)

    • Flip upload --intrinsic to default true. Rejected: intrinsic upload requires an io.yaml, and the CLI has no generator for one. It would block plain-PEFT users at the upload step, add a mandatory artifact, and require a deprecation cycle — it moves the failure earlier rather than fixing it.
    • Add an explicit --intrinsic flag to add-readme only. Rejected: it only helps users who already know the requirement, which is the gap m alora upload's default layout is incompatible with add-readme's generated usage code #1620 reports. It survives as the --layout override for scripted use.
    • Detect and refuse when the repo is flat. Rejected: plain PEFT publishing is a stated legitimate use case, so flat users would have no way to generate a README.
    • Detect and omit the integration code when flat. Rejected: correct but less useful. A small, compiled PEFT sample costs little and keeps the README actionable.
    • Keep generating intrinsic code and only strengthen warnings. Rejected: the template already carries a layout caveat from feat(backends): accept composed Adapter directly (Epic #929, issue #1144, PR1) #1619, and the reported failure still occurred.
    • Require auth before generation so detection can always run. Rejected: that removes local, unauthenticated generation, which worked before this change.
    • Use the local weights directory instead of inspecting the remote repo. Not taken: add-readme does not accept a weights path, so this is a larger signature change. The --layout override covers the same need without it.
    • Bundle the adjacent template fixes (hardcoded base model, hardcoded LoRA/aLoRA type, dead --io-yaml). Deferred to keep the layout change reviewable.
  6. planetf1 commented on Nov 16, 2026

    @planetf1
    ContributorAuthor

    Thanks Mark, this is the right shape: detect, allow an override, leave upload's default alone, and give flat repos a README that works. Agree with D1 to D5. A couple of things beyond your questions first, then answers.

    Sequencing with #1798. #1798 fixes #1791 by replacing HfFolder.get_token() in commands.py, upload.py and intrinsic_uploader.py. Your prototype moves that same lookup in alora_add_readme, so the two will conflict. I'd let #1798 merge first and rebase onto it. The new tests then exercise the real token path and the HfFolder stubs can go.

    The flat sample doesn't exercise the adapter. It stops after from_pretrained, so it runs but shows nothing. There's a subtler problem for aLoRA: the adapter only activates once the invocation tokens appear in the input, and training used a specific prompt shape (train.py:89):

    f"{item}\nRequirement: <|end_of_text|>\n{invocation_prompt}"

    A reader who calls generate() on plain text gets base-model output and thinks the adapter is broken. The sample should build that prompt and decode the reply, roughly:

    # unverified sketch
    prompt = f"{item}\nRequirement: <|end_of_text|>\n{invocation_prompt}"
    inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False)
    out = model.generate(**inputs, max_new_tokens=32)
    print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))

    add-readme already takes --promptfile, so the invocation string is known (default <|start_of_role|>check_requirement<|end_of_role|>), and the first dataset sample can fill item the same way example_call_kwargs does for the intrinsic branch.

    Q2, prefix vs full path. The prefix check is right for classifying, but it can say "intrinsic" for a repo the sample still can't load. The loader resolves <name>/<canonical base model>/<type>/ from the backend's base model, so a nested upload trained on a different base model, or with a base-model name that normalizes differently, passes your check and still fails. The reasons given for not checking the full path don't hold, because adapter_subpath() in mellea/formatters/granite/intrinsics/util.py already does both jobs:

    • it applies BASE_MODEL_TO_CANONICAL_NAME, so no normalization to reimplement;
    • the old layout only applies to repos listed in OLD_LAYOUT_REPOS (the IBM collections), and upload --intrinsic never writes it, so user repos can't hit it anyway.

    --basemodel is already required, so after the prefix check:

    matches = [
        t for t in ("lora", "alora")
        if any(f.startswith(adapter_subpath(intrinsic_name, basemodel, repo_id, adapter_type=t) + "/") for f in repo_files)
    ]

    No match means warn: the README will be generated but its code won't find the weights for that base model. One match also tells us the adapter type, which fixes the hardcoded AdapterType.ALORA in auto mode for free. Explicit --layout intrinsic would still need the type from somewhere; that can stay a follow-up.

    Q1 / Q4, non-interactive runs. Same answer for both. If stdin is a TTY, prompt as the prototype does. Otherwise exit non-zero with a message naming --layout intrinsic|flat. Waiting on input() in CI either hangs or dies with EOFError, which is what the existing upload confirmation already does, so an early, explicit failure is strictly better. Scripted users pass --layout and never see the prompt.

    Q3, flag naming. --layout auto|intrinsic|flat reads fine. I'd avoid peft as a value: both layouts hold PEFT adapters, the difference is where the files sit. flat also matches the wording in the new upload warning.

    Q5, framing in flat mode. Drop it fully. A flat repo isn't usable as an intrinsic, so the README shouldn't describe it as one: the heading (already done), the "intrinsic adapter" wording in the generator prompt (readme_generator.py:217 and :228), which steers the LLM's description, and the "Upload intrinsic README." commit message. Keep the mellea tag, since it marks where the adapter came from rather than how it loads.

    Q6, follow-ups. I'd fold the base-model hardcode into this change. __main__ builds LocalHFBackend(IBM_GRANITE_4_1_3B), and the loader looks for weights under the backend's base model, so for an adapter trained on anything else the README's own code fails with the same not found error this issue is about. base_model is already a template variable and LocalHFBackend takes a plain string, so it's a one-line change. The adapter-type hardcode is mostly covered by Q2 above. The unused --io-yaml on add-readme is unrelated to layout; a separate small issue is fine.

  7. added a commit that references this issue on Nov 20, 2026
    133f85c
  8. markstur commented on Nov 20, 2026

    @markstur
    Contributor

    Thanks. Agreed on these, nothing to add. The plan would be:

    • Sequencing: build on fix(cli): use supported Hub token lookup for aLoRA uploads #1798 (merged) for the token lookup.
    • Q1/Q4: a TTY would get the prompt. Otherwise the command would exit non-zero before generating, naming --layout intrinsic|flat.
    • Q3: keep --layout auto|intrinsic|flat.
    • Q5: flat mode would drop the intrinsic framing: the heading, the generator prompt wording and the upload commit message. The mellea tag stays.
    • Q6: the runnable block would use --basemodel, detection would cover the adapter-type hardcode, and --io-yaml is tracked in bug: m alora add-readme accepts --io-yaml but never uses it #1860.
    • Flat sample: it would build the training prompt (first dataset item plus the invocation string from --promptfile) and decode only the reply.
    • Still open: an explicit --layout intrinsic would keep documenting alora. A way to state the type stays a follow-up, as you suggested.

    Q2 and one small addition are in separate comments.

  9. markstur commented on Nov 20, 2026

    @markstur
    Contributor

    Q2

    Agreed: the prefix would classify the layout, the exact directory would decide, a miss would warn but still generate the README, and the matching directory would give the adapter type.

    One adjustment to the adapter_subpath() call: look up the base model by its last path component, as LocalHFBackend.base_model_name and upload --intrinsic already do. adapter_subpath() only shortens the IDs in BASE_MODEL_TO_CANONICAL_NAME. Passing myorg/my-finetune straight through would look in <name>/myorg/my-finetune/…, while the loader and uploader use <name>/my-finetune/….

    That derivation would then exist in three places (backend, uploader, this check). I'd leave them as they are unless you'd prefer a shared helper.

  10. markstur commented on Nov 20, 2026

    @markstur
    Contributor

    Hub reads in --layout auto

    --layout auto would make read-only Hub requests with the user's token before anything is generated or confirmed. It would skip them without a token, and nothing would be written before the existing upload confirmation.

    • File listing: this is how detection works, as discussed.
    • Flat repos only (the addition): the root adapter_config.json, one small file, to say LoRA vs aLoRA. A flat repo has no directory to read the type from. The type would come from whether alora_invocation_tokens has a value, because PEFT 0.19.1 writes the key as null for a plain LoRA. If the file couldn't be read, the README would say nothing about the type.

    To keep these visible, I'd:

    • print a line before each request
    • download the config into a temporary directory, not the shared Hugging Face cache
    • say in the --layout help that intrinsic and flat make no requests
    • word not-found as "may not exist, or your token may not have access", since the Hub reports private repos the same way

    Are the extra read and this handling acceptable?

  11. planetf1 commented on Nov 24, 2026

    @planetf1
    ContributorAuthor

    Happy with this overall. One change I'd ask for, then answers to your questions and two small doc points.

    Please add a timeout to the file listing

    list_repo_files has no timeout, and the Hub client has none either. If the connection accepts and then goes quiet (a dead proxy, a captive portal), add-readme just sits there before it generates anything. I checked this against a local server that never replies: still blocked after 20 seconds. The config download is fine, since it already has a 10 second limit by default.

    HfApi().model_info(name, token=token, timeout=5).siblings takes a timeout, and it gave the same file list as list_repo_files on the two public repos I compared. If it times out, the existing except Exception already treats the layout as unknown and asks, the same as when there's no token. A message that says it timed out would help, plus a test that makes model_info raise httpx.TimeoutException and checks the question gets asked (and that the no-terminal error fires when it can't ask).

    Your questions

    • Reads with the token, none without one: fine. I looked at anonymous reads for logged-out users and wouldn't add them. m alora upload always creates private repos, so in the normal flow an anonymous listing would just say "not found".
    • Config read for flat repos: fine. It only picks between the aLoRA and LoRA wording in the README, and the wording for "unknown" already exists, so dropping it later would cost one sentence.
    • Temp directory: I tried hf_hub_download(..., cache_dir=<tmp>) on a small public adapter repo and nothing appeared in ~/.cache/huggingface. I haven't tried a Xet-backed file.
    • Printed lines, --layout help and the not-found wording: all good. The code in fix(cli): match m alora add-readme to the repository's adapter layout #1861 does what you describe.
    • Shared helper: not in this PR. The three derivations agree for Hub IDs, and it can be tidied separately if it starts to matter.

    Docs

    The docstring, --layout help and example README match the code. Two gaps:

    • No token and no terminal are only partly covered. The docstring explains the no-terminal error; the help text and example README don't. Nothing says that without a token auto skips the requests and asks instead, and "Prerequisites" reads as if a token is needed from the start. One sentence in the docstring would cover both.
    • docs/docs/advanced/lora-and-alora-adapters.md says to pass --intrinsic "if you intend to use the adapter as a Mellea adapter function", but never says a plain upload can't be loaded that way. That's the original gap in this issue. Two lines would fix it, here or in a follow-up, your call.

    One separate bug

    m alora upload --intrinsic picks lora or alora with "alora_invocation_tokens" in config (in alora_upload, cli/alora/commands.py). PEFT 0.19.1 always writes that key, with null for a plain LoRA (I saved both kinds to check), so a plain LoRA goes up under alora/. Your adapter_type_from_config tests the value, which is the right check. I'd fix the upload side with the same helper as its own small change, since it alters what upload does.

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

Metadata

Metadata

Assignees

Labels

area/aloraarea/clibugneeds-designp2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions