Documentation
¶
Overview ¶
Package peft implements parameter-efficient fine-tuning layers for GoMLX.
Index ¶
Constants ¶
const ( // ParamAdapter is the name of the LoRA adapter to use. // If empty (""), PEFT is inactive and base layers are trainable as normal. // If set to "off", "disabled", "false", or "none", base layers are frozen without adding any LoRA adapters. // Otherwise, it defines the sub-scope name for the LoRA adapter variables (e.g. "lora", "task_a"). ParamAdapter = "peft_adapter" // ParamTargetModules specifies substrings of scope paths to which LoRA adapters should be applied. // Can be a []string or a comma/semicolon/space-separated string (e.g. "query,value"). // Unmatched linear projections have their base weights frozen, but no adapter added. // If empty, all linear projections with peft_adapter set will receive adapters. ParamTargetModules = "peft_target_modules" // ParamRank is the LoRA rank. Zero disables the adapter, which is the default. ParamRank = "peft_rank" // ParamAlpha is the LoRA scaling numerator. It defaults to ParamRank. ParamAlpha = "peft_alpha" // ParamDropout is the LoRA dropout rate. It defaults to zero. ParamDropout = "peft_dropout" // ParamBias controls whether the base projection bias is trainable. ParamBias = "peft_bias" )
Variables ¶
This section is empty.
Functions ¶
func IsAdapterDisabled ¶
IsAdapterDisabled returns true if the adapter name explicitly disables adapter creation (i.e. "off", "disabled", "false", or "none", case-insensitive). Note: An empty adapter name means PEFT is inactive, not disabled/freeze-only.
func MatchesTargetModule ¶
MatchesTargetModule returns true if targets is empty or if any target is contained within scopePath.
func ParseTargetModules ¶
ParseTargetModules converts a target modules value (either []string or string) into a normalized string slice.
Types ¶
type BiasMode ¶
type BiasMode uint8
BiasMode controls whether a projection bias is trainable with its LoRA weights.
type Linear ¶
type Linear struct {
// contains filtered or unexported fields
}
Linear is a graph-building LoRA projection. Configure it with scope hyperparameters, then call Done.
func New ¶
New configures a LoRA projection around an existing dense weight. The base projection remains unchanged when ParamRank is zero.
func (*Linear) Done ¶
func (l *Linear) Done() *Node
Done builds the frozen base projection plus its LoRA update. A and B live in scope/<adapterName>, use the Store RNG, and are included automatically in normal trainable-variable selection.
func (*Linear) WithWeightLayout ¶
func (l *Linear) WithWeightLayout(layout compute.DenseLayout) *Linear
WithWeightLayout configures the layout of the existing base weight.
type NF4 ¶
type NF4 struct {
// contains filtered or unexported fields
}
NF4 is a graph-building QLoRA projection. Configure its LoRA update with the same scope parameters as New, then call Done.
type NF4Weight ¶
type NF4Weight struct {
InputFeatures, OutputFeatures int
BlockSize int
Packed []byte
Scales []float32
ScaleCodes []byte
ScaleScales []float32
ScaleBlockSize int
}
NF4Weight stores a frozen [input, output] NormalFloat4 matrix. Packed holds two NF4 codes per byte. Scales are per-input, per-output-block absolute-max scales; ScaleCodes/ScaleScales replace Scales when double quantization is on.