FMS Acceleration using Fused Operations and Kernels
Project description
FMS Acceleration for Fused Operations and Kernels
This library contains fused operations and custom kernels, to be expanded over time. Currently it contains the following:
- Fused operations and kernels extracted from unsloth.
- Low-Rank Adapter Fused Operations
- Fast RoPE Triton Kernels
- Fast RMS LayerNorm Triton Kernels
- Fast Cross Entropy Triton Kernels
Plugins
| Plugin | Description | Depends | Loading | Augmentation | Callbacks |
|---|---|---|---|---|---|
| fast_kernels | Enhanced version of fast_quantized_peft, also works for full-FT and non-quant peft |
Contains extracted code | ✅ |
Supported DataType Settings
Compatibility Matrix with Mixed Precision
| torch_dtype | Mixed Precision | Full-FT-FOAK | PEFT-FOAK | QPEFT-FOAK |
|---|---|---|---|---|
| FLOAT16 | - | Compatible | Compatible | ✗ |
| FLOAT16 | FP16 | ValueError: Attempting to unscale FP16 gradients. See here |
Compatible | Compatible |
| BFLOAT16 | - | Compatible | Compatible | ✗ |
| BFLOAT16 | BF16 | Compatible | Compatible | Less Performant |
NOTE: this chart is also a good reference for supported types, even for the non-FOAK case.
Code Extracted from Unsloth
Notes on the extraction of code from unsloth:
- While unsloth is released under Apache 2.0, there are comments indicating some exceptions strewn throughout the code base, see an example here.
it would require a commercial license if used to run on more than 4 GPUs ... - These exceptions appear to be located around the trainer improvements, see another example here.
- These exceptions appear around Feb 2024 Release; any code that appears in any file where such exceptions occur is not extracted.
- Instead in its place, we have adopted a different approach; we adopt the approach of model patching, as opposed unsloths' approach to rewrite the model. Our approach is novel and completely rewritten from scratch.
- We have also enabled dropout on the lora fused operations.
- All extracted code appears before the Feb 2024 Release.
- In the table below we record what was extracted, and the exact commit from which it was taken.
| Path | Description | Extracted From | Modifications | Date |
|---|---|---|---|---|
| fused_ops/unsloth_lora | QLoRA fast dequant, activation kernels | unsloth/main @ 1ecc0185 |
28 Jan 2024 | |
| fused_ops/unsloth_lora/bnb | BNB fast lora | unsloth/main @ 1ecc0185 |
fast_lora.py |
28 Jan 2024 |
| fused_ops/unsloth_lora/gptq | GPTQ fast dequant (triton_v2) | jeromeku/main @ 2839d39 |
fast_lora.pytriton/layers.py |
6 Feb 2024 |
| kernels/unsloth | Fast RMS, RoPE, CrossEnt kernels | unsloth/main @ 1ecc0185 |
cross_entropy_loss.pyrms_layernorm.py |
28 Jan 2024 |
Supported Models
| Model | norm | pos emb | cross-ent | fused_lora |
|---|---|---|---|---|
LlamaForCausalLM |
✅ | ✅ | ✅ | ✅ |
MistralForCausalLM |
✅ | ✅ | ✅ | ✅ |
MixtralForCausalLM |
✅ | ✅ | ✅ | ✅ |
GPTBigCodeForCausalLM |
❌ | ❌ | ✅ | ❌ |
GraniteForCausalLM |
✅ | ✅ | ✅ | ✅ |
Adding Support For A New Model
It is realtively easy by following an existing template, in what follows we use GraniteForCausalLM as an example.
- implement a
get_mp_rulesfor the new model, which returns a list ofModelPatcherRule. - logic that needs to be changed is the various classes that the rules are triggered on. Import the various module classes likes so:
from transformers.models.granite.modeling_granite import ( GraniteAttention, GraniteMLP, GraniteRMSNorm, )
- replace the classes appropriately in various locations in
ModelPatcherRule. In particular theModelPatcherTriggerportions of it. Namerule_idappropriately.ModelPatcherRule( rule_id="granite-rms", trigger=ModelPatcherTrigger(check=GraniteRMSNorm), forward=fast_rms_layernorm, )
Running Liger Kernel Benchmarks
Using the scenarios-liger.yaml, this will run full fine tuning, lora peft, autoGPTQ lora peft, and bits-and-bytes lora peft with the triton kernels (Fast RMS, RoPE, CrossEnt) as a base and then run with the liger kernel for LigerFusedLinearCrossEntropy as well as Fast RMS, RoPE to compare results. It only runs against mistral and llama models.
The benchmarks were ran separately for each num_gpu entry; they can be run together in a single command, but this is more efficient.
tox -e run-benches -- 1 "4 8 16 32" benchmark_outputs_1 scenarios-liger.yaml none
tox -e run-benches -- 2 "8 16 32 64" benchmark_outputs_2 scenarios-liger.yaml none
tox -e run-benches -- 4 "16 32 64 128" benchmark_outputs_3 scenarios-liger.yaml none
Known Issues
- MixedPrecision
--fp16or--bf16should be used withfast_lora. fast_lorahas issues with FSDP V1 with thepeftstyle of FSDP wrapping.- This is because the adapter's forward functions are bypassed in the fused ops.
- For AutoGPTQ/QLoRA this is addressed by distributing the adapters using DDP so they will be unsharded in time for the fused ops.
fast_rope_embeddingsdoes not work withpostion_ids, it seems like HF has depracated passing these ids into the rope embedding methods.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fms_acceleration_foak-0.7.3-py3-none-any.whl.
File metadata
- Download URL: fms_acceleration_foak-0.7.3-py3-none-any.whl
- Upload date:
- Size: 68.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02a4b4bf9a2960d2f3c8df610661e3853e0b396255912231d503d204305f75a3
|
|
| MD5 |
3d1833ecb27c56441becf007043b1663
|
|
| BLAKE2b-256 |
0c1aa603cc3cf44a7707aa52a967de59c6558dd77f62f72f2dbcdc43e3be3e94
|
Provenance
The following attestation bundles were made for fms_acceleration_foak-0.7.3-py3-none-any.whl:
Publisher:
build-and-publish.yml on foundation-model-stack/fms-acceleration
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fms_acceleration_foak-0.7.3-py3-none-any.whl -
Subject digest:
02a4b4bf9a2960d2f3c8df610661e3853e0b396255912231d503d204305f75a3 - Sigstore transparency entry: 726649426
- Sigstore integration time:
-
Permalink:
foundation-model-stack/fms-acceleration@2e8ed1868e51f73bc09a55102d9244afed47ab0b -
Branch / Tag:
refs/tags/v0.6.3.4 - Owner: https://github.com/foundation-model-stack
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-publish.yml@2e8ed1868e51f73bc09a55102d9244afed47ab0b -
Trigger Event:
release
-
Statement type: