Repository navigation
Description
This issue might be capturing my own misconcptions about the current state of the code-base.
I'm opening the issue to get feedback from @jakelorocco and @frreiss. It's possible that I am misunderstanding things and all that's needed is better documentation. If that's the case, then we can probably iterate on this issue description to explain how things work (or should work).
If I state anything false or misleading in this issue, please quote and explain what I have wrong.
The Immediate Problem
While fixing issues related to our m tune command (see PR #422 ), I found that none of our custom alora stuff has worked since the intrinsics change.
(These examples aren't in the code-base's test suite because they require training and loading a custom model; we should find a way to mock that someone in the future.)
The cause for the break is as follows:
- all requirement checking adapters must be intrinsics, but
- all intrinsics must be listed in
_INTRINSICS_CATALOG_ENTRIES, and - there is no way to add custom stuff to
_INTRINSICS_CATALOG_ENTRIES(and even if there were that would be ugly).
The failure point is in the Intrinsic.__init__ call within the AloraRequirement initializer:
Intrinsic.__init__(
self,
intrinsic_name=intrinsic_name,
intrinsic_kwargs={"requirement": f"{self.description}"},
)which calls adapters.catalog.fetch_intrinsic_metadata(intrinsic_name: str) function, which does a lookup against the _INTRINSICS_CATALOG_ENTRIES table. This means that you cannot use any adapter for requirement checking that is not part of the _INTRINSICS_CATALOG_ENTRIES table. That's a problem because we might want custom lora/alora requirement checkers that are implemented as adapters (as in the canonical stembolt example).
I tried to hack around this by adding to the catalog, but that also failed because the adapter must be a GraniteCommonAdapter (huggingface.py:354), which opened another whole can of worms.
Larger Issue
After digging through the current Intrinsic code-base, I think this is a symptom of a larger problem. We have not done a proper job at documenting the architectural choices associated with intrinsics and adapters. We may have also made some bad decisions, but I'm not sure because I am still not quite sure how everything is supposed to work.
I'm capturing some other alora questions here, which aren't directly related to getting m tune working again.
- It's unclear to me how you're supposed to write the logic for activating a generic adapter without turning it into an intrinsic. Our current training code doesn't auto-generate the JSONs for eg activation sequences (trivial to fix), and I think you might also need to modify granite.common itself in order to use a custom adapter, at least for our current code base (less trivial to fix / does require some redesign). In any case, it should be possible to train an adapter and use it to implement a component's generation without bundling it as an intrinsic. Open to being
- We tout that the primary advantage of aloras is that you re-use kv cache, but then implement aloras in terms of chat rewrites. If you rewite prior history, then you have to recompute kv cache anyways. So why not use a LoRA?
- Our code currently allows the use of multiple aLoRAs against a single model. The original paper states that this is not possible. Have changed since then / do we have changes in the pipeline to enable this? If not, we should enforce the invariant that only one alora may be loaded / used with any particular backend. You must unload the old alora before loading the new one, and that triggers a cache invalidation.
Activity
nrfulton commentedon Feb 8, 2026
Note: there are other hacky solutions, or perhaps even principled incremental (small bug fix) solutions. The larger issue I'm trying to point out is that the way that this whole system works is opaque and not very well documented.
[-]Cannot use custom adapters because Intrinsics and Adapters are conflated[/-][+]Cannot use custom adapters because Intrinsics and Adapters are conflated, and missing documentation[/+]nrfulton commentedon Feb 8, 2026
Below I capture a proposed re-design. I want to first address the top-level concerns; it may not make sense to proceed down this path, so I'm burying it in a comment for now.
Proposed Solution
we've conflated intrinsics and adapters, or perhaps prioritized intrinsics over adapters.
I think that the actual substantive difference between an intrinsic and any other (alora) adapter is that intrinsics ship with three things:
So "Intrinsic", in the current code-base, is just a really name for concept of a JSON file format and unique name which together entail a checkpoint, an activation sequence, and some chat rewrite logic. This means that it's a specific implementation of an Adapter.
AFAICT, there is no way to use a LoRA or aLoRA adapter that isn't shipped exactly the way that granite intrinsics are shipped. This is a problem because approximately all current users of LoRAs do not do things in the granite intrinsics way. For this reason, our code base should treat intrinsics as a special case of adapters -- not the other way around.
In mu proposed alternative design, we have
Adapters andAdapterBackedComponents. Intrinsics are just special cases of both that implement theAdapterinterface / behavior using thename, JSON, granite.common impldiscussed above.My belief is that
and any
action : Componentbacked by an intrinsic is ultimately backed by a particular type ofAdapter, so there does not even need to exist anIntrinsicBackedComponent. Those are justAdapterBackedComponents whose adapters happen to be of typeIntrinsic. I.e., what we currently call anIntrinsicis just aAdapterBackedComponentwhose adapter happens to be an intrinsic.I'll briefly sketch the adapter lifecycle and protocol, both because that's the basis of my belief and because we should flesh this out and document it somewhere (probably in
docs/rewrite/adapters_and_intrinsics.mdwith corresponding examples).Adapter Lifecycle
Adapters have a lifecycle that's mostly identical to how things work now. Parts of this protocol might need to be implemented in the backend rather than in the intrinsic. I'm not sure exactly what the split is; I think @jakelorocco has the most context to answer that question.
Loading (done by backends)
Activation (done by backends)
Deactivation (done by backends)
Preparing (done by Adapaters or backends? IDK)
Specifics of Proposed Change
AdapterBackedComponent
The only way to use an adapter (therefore, intrinsic) is by passing an
AdapaterBackedComponentas the action.The
AdapterBackedComponentis just aComponentwith anadapter : str | Adapterproperty. The union type works like our model_ids -- if it's a str then we look it up in the_INTRINSICS_CATALOG_ENTRIESbut otherwise we use the adapter.For example, from the current code base, we would need
ALoRARequirement <: AdapaterBackedComponentwithadapter="requirement_checking"by default.This solves the lookup problem that led to my deep-dive of the curretn adapter/intrinsics code base.
Intrinsics
There is an
IntrinsicAdapter <: Adapterwhich uses the Intrinsic JSON format to implement each of the methods. the backend might also dispatch on this subtype to do special handling if necessary (although I think this should not be necessary becauseAdapter.rewriteshould do everything that's intrinsic-specific).For example, there is no
There is only
which operates over things that implement the
AdapterBackedComponentinterface using things that implement theAdapterinterface.@jakelorocco please let me know what you think.
Other design considerations:
[-]Cannot use custom adapters because Intrinsics and Adapters are conflated, and missing documentation[/-][+]Adapter code is over-specialized to Intrinsics.[/+][-]Adapter code is over-specialized to Intrinsics.[/-][+]Adapter code is undocumented and over-specialized to Intrinsics.[/+]nrfulton commentedon Feb 8, 2026
I went ahead and hacked up some dicts and upload a model to huggingface, leaving a trace of issues as I worked. I now need a
io.yamlfile but cannot figure out what's supposed to go in those files or what the semantics are even after reviewing all of the ones in the rag lib. Do we have infra for bundling and uploading these intrinsic huggingface repo things?Edit: figured out the io.yaml format. It looks like all intrinsics must return json; is that correct?
frreiss commentedon Feb 10, 2026
Yes, the returned value must adhere to a JSON Schema schema that is compatible with XGrammar constrained decoding. Attempts to use other output formats have resulted in considerable pain.
frreiss commentedon Feb 10, 2026
vLLM supports multiple LoRA adapters within a single batch, and the aLoRA fork of vLLM extends this capability to activated LoRA. The aLoRA fork can reuse cached KV prefixes from the base model while generating new tokens with multiple aLoRA adapters in parallel.
If you are using Hugging Face Transformers for inference, performance is going to be poor regardless of the caching strategy. There is too much latency from alternating between GPU, C++ CPU, and Python CPU computation.
nrfulton commentedon Feb 10, 2026
Reasonable; my experience with existing models is similar. The LLMON folks are making good progress, so this appears to be an artifact of training regimes rather than a fundamental limitation (no surprises there, just observing.)
In the meantime: currently granite common doesn't enforce a grammar but does always insist on the output at least being valid json due to a
json.loadscall (or similar) during post-processing.This means that we can't use the intrinsics code with a lora/alora that was not trained on JSON.
Could we do one of the following:
io.yamlthat specifies "no schema"template: nullas "no grammatical constraint"Either way works for me.
I'm open to counter-arguments.
We can also move this discussion to granite-common.
nrfulton commentedon Feb 10, 2026
Thanks for the rundown, that's helpful.
But after talking with a few people I realized that the load/unload isn't necessary, because if you want to marshal stuff between aloras I guess you do that like this (pseudocode with hallucinated method names obviously):
Yeah, we know.
We maintain the transformers backend because it is still a lingua franc for many researchers, and we want to be able to build out runtime features against model capabilities that aren't yet available in llama.cpp or ollama or vllm. Not because we expect deployment against that backend.
The thing I was observing was the cost of the additional prefill below the "key point" comment above, which is essential and not wrt any particular engine.
nrfulton commentedon Feb 11, 2026
Additional note: I am not sure how Intrinsic kwargs are supposed to work. Are these the arguments to the intrinsic?
In any case, we should probably intantiate an
IntrinsicThingie(maybeIntrinsic) which is not a Componet but has a__call__which returns anIntrinsicCallwhich is aComponent.But I'm not sure. I'm working an example and will include comments there (
102_example.pyin the examples/aLora directory, will be merged tmw).But I'm definitely open to correction on this. And it's just an ergonomics thing.
Having the type variable for
Componentbound at the definition ofIntrinsicis also unfortunate, because many intrinsic have a template and an object with fields corresponding to that template should be the parsed_repr type.jakelorocco commentedon Feb 11, 2026
Yes, intrinsic kwargs are kwargs that are passed into the rewrite / transform method when generating using an intrinsic. They are "necessary" for the intrinsic to function correctly. For instance, a requirement check alora needs it's requirement passed as a kwarg to that transform function.
I would have to see an example of the IntrinsicThingie -> IntrinsicCall to weigh in. I'm not exactly sure what this means / would look like. Our current implementation of the Intrinsic / rag calls was done to have a more "functional" approach. But we can define specific classes for each Intrinsic if desired.
Agreed, this is an unfortunate limitation of python's type system. We can change the way intrinsics are defined by
psschwei commentedon May 12, 2026
superseded
psschwei commentedon May 12, 2026
#929