Rerouting Requirement Actions in Backend.generate_* calls
Backend will often re-route a generate call where action : Requirement to an ALora. This document explains how and why that happens.
The Requirement Rerouting Rule
The Simple Rule
The simplest version of the Requirement Rerouting Rule is:
The most specific constraint checking method will be used when validating generic Requirements.
The actual rule is slightly more complicated.
The Actual Rule
If aRequirement is validated using a backend that could either use a requirement_check aLoRA or perform an LLMaJ prompt on the underlying model, then the aLoRA is used for validation, even if the backend.generate_from_context method is called instead of the backend._generate_from_intrinsic method.
There are three exceptions to this rule:
Backend.default_to_constraint_checking_alorais set toFalse(this parameter defaults toTrue).- The
Requirementhas a more specific subtype that indicates a more specific intent (LLMaJRequirement). - The
ALoRArequirement checker throws an exception.
ALoRARequirement, then the backend.generate_from_context call is rerouted to the constraint checking LoRA, regardless of the value of default_to_constraint_checking_alora.
Decision Rationale
Background and Problem Statement
Thestdlib has a Requirement class whose validate behavior is an LLMaJ call.
Suppose that the user creates a backend and then adds a generic constraint checking aLoRA:
Alternatives to the Proposed Rule
- Avoid the problem by forcing the user to be more explicit.
- Respect control flow in the backends/alora mixins, and have the MelleaSession or the user explicitly implement the appropriate control flow.
- Have the
Requirement.validateimplementation specify whatever control flow is desired for that particular requirement.
Advantages
- Reduced cognitive load. To first approximation, there is a simple rule that produces unsurprising results. The exceptions are rare and require explicit intervention from the user. If these exceptions are used, the user almost certainly knows exactly what they are doing.
- Control is retained. If the user wants to specify the precise semantics of their validate call, then they can use the mpore specific
LLMaJRequirementandALoraRequirementclasses. - The backend is the one that needs to make the choice about whether to handle KV cache.
Disadvantages
All backends that implement the aLoRA mixin need to implement this semantics.- This might be a blessing in disguise. It’s actually not clear that ALora context construction can be done WLOG outside of the specific backend.
- That code is written rarely in any case.
- Depending on the truth of the first bullet point’s conjecture, we can mitigate by implementing this routing in
m.validateso that even if a backend contributor gets this wrong the proper behavior is still usually observed by most users.