slicktune.strategies

Parameter-update strategies (how weights change).

Classes

AdaLoRAStrategy

AdaLoRA: adaptive-rank LoRA that prunes toward target_r.

DoRAStrategy

DoRA (Weight-Decomposed LoRA) PEFT strategy.

FullStrategy

Full fine-tuning: update all model parameters.

LoRAStrategy

LoRA PEFT strategy (default production PEFT path).

QLoRAStrategy

QLoRA strategy: 4-bit quantized base + LoRA adapters.

Package Contents

class slicktune.strategies.AdaLoRAStrategy[source]

Bases: slicktune.types.Strategy

AdaLoRA: adaptive-rank LoRA that prunes toward target_r.

Parameters:
  • target_r (int, optional) – Average target rank budget, by default 8.

  • init_r (int, optional) – Initial rank before pruning, by default 12.

  • alpha (int, optional) – LoRA scaling alpha, by default 32.

  • dropout (float, optional) – LoRA dropout probability, by default 0.05.

  • target_modules (list[str] | str | None, optional) – Modules to adapt, by default "all-linear".

  • bias ({“none”, “all”, “lora_only”}, optional) – Bias training mode, by default "none".

  • tinit (int, optional) – Warmup steps before rank allocation, by default 0.

  • tfinal (int, optional) – Final fine-tuning steps at fixed rank, by default 0.

  • deltaT (int, optional) – Rank allocation interval, by default 10.

  • total_step (int, optional) – Expected optimizer steps (required by PEFT AdaLoRA), by default 1000. Prefer setting this close to steps_per_epoch * epochs.

__slots__ = ()
alpha: int = 32
apply(model: Any) Any[source]

Attach AdaLoRA adapters to model.

Parameters:

model (Any) – Hugging Face causal LM.

Returns:

Any – PEFT-wrapped AdaLoRA model.

Raises:

ValueError – If total_step is not positive.

bias: BiasType = 'none'
deltaT: int = 10
dropout: float = 0.05
init_r: int = 12
load_kwargs() dict[str, Any][source]

Return empty load kwargs.

Returns:

dict[str, Any] – Empty mapping.

name: str = 'adalora'
target_modules: list[str] | str | None = 'all-linear'
target_r: int = 8
tfinal: int = 0
tinit: int = 0
total_step: int = 1000
class slicktune.strategies.DoRAStrategy[source]

Bases: slicktune.types.Strategy

DoRA (Weight-Decomposed LoRA) PEFT strategy.

Same knobs as LoRA with use_dora=True for magnitude/direction decomposition.

Parameters:
  • r (int, optional) – LoRA rank, by default 16.

  • alpha (int, optional) – LoRA scaling alpha, by default 32.

  • dropout (float, optional) – LoRA dropout probability, by default 0.05.

  • target_modules (list[str] | str | None, optional) – Modules to adapt, by default "all-linear".

  • bias ({“none”, “all”, “lora_only”}, optional) – Bias training mode, by default "none".

__slots__ = ()
alpha: int = 32
apply(model: Any) Any[source]

Attach DoRA adapters to model.

Parameters:

model (Any) – Hugging Face causal LM.

Returns:

Any – PEFT-wrapped DoRA model.

bias: BiasType = 'none'
dropout: float = 0.05
load_kwargs() dict[str, Any][source]

Return empty load kwargs.

Returns:

dict[str, Any] – Empty mapping.

name: str = 'dora'
r: int = 16
target_modules: list[str] | str | None = 'all-linear'
class slicktune.strategies.FullStrategy[source]

Bases: slicktune.types.Strategy

Full fine-tuning: update all model parameters.

Parameters:

None

__slots__ = ()
apply(model: Any) Any[source]

Enable gradients on all parameters.

Parameters:

model (Any) – Hugging Face causal LM.

Returns:

Any – The same model with requires_grad=True on all params.

load_kwargs() dict[str, Any][source]

Return empty load kwargs.

Returns:

dict[str, Any] – Empty mapping.

name: str = 'full'
class slicktune.strategies.LoRAStrategy[source]

Bases: slicktune.types.Strategy

LoRA PEFT strategy (default production PEFT path).

Parameters:
  • r (int, optional) – LoRA rank, by default 16.

  • alpha (int, optional) – LoRA scaling alpha, by default 32.

  • dropout (float, optional) – LoRA dropout probability, by default 0.05.

  • target_modules (list[str] | str | None, optional) – Modules to adapt. "all-linear" lets PEFT discover linear layers, by default "all-linear".

  • bias ({“none”, “all”, “lora_only”}, optional) – Bias training mode passed to PEFT, by default "none".

__slots__ = ()
alpha: int = 32
apply(model: Any) Any[source]

Attach LoRA adapters to model.

Parameters:

model (Any) – Hugging Face causal LM.

Returns:

Any – PEFT-wrapped model.

bias: BiasType = 'none'
dropout: float = 0.05
load_kwargs() dict[str, Any][source]

Return empty load kwargs (bf16/fp16 decided by the trainer).

Returns:

dict[str, Any] – Empty mapping; LoRA does not require special load flags.

name: str = 'lora'
r: int = 16
target_modules: list[str] | str | None = 'all-linear'
class slicktune.strategies.QLoRAStrategy[source]

Bases: slicktune.types.Strategy

QLoRA strategy: 4-bit quantized base + LoRA adapters.

Requires CUDA and optional extra slicktune[qlora] (bitsandbytes).

Parameters:
  • r (int, optional) – LoRA rank, by default 16.

  • alpha (int, optional) – LoRA scaling alpha, by default 32.

  • dropout (float, optional) – LoRA dropout probability, by default 0.05.

  • target_modules (list[str] | str | None, optional) – Modules to adapt, by default "all-linear".

  • bias ({“none”, “all”, “lora_only”}, optional) – Bias training mode, by default "none".

__slots__ = ()
alpha: int = 32
apply(model: Any) Any[source]

Prepare a 4-bit model and attach LoRA adapters.

Parameters:

model (Any) – Quantized Hugging Face causal LM.

Returns:

Any – PEFT-wrapped QLoRA model.

bias: BiasType = 'none'
dropout: float = 0.05
load_kwargs() dict[str, Any][source]

Return bitsandbytes 4-bit quantization config for model load.

Returns:

dict[str, Any]quantization_config suitable for from_pretrained.

Raises:
name: str = 'qlora'
r: int = 16
target_modules: list[str] | str | None = 'all-linear'