Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be00978bc2 | ||
|
|
3738978394 | ||
|
|
6132a30cda | ||
|
|
3dd86d35b8 | ||
|
|
dd9ebaeba1 | ||
|
|
fc4e37920b | ||
|
|
a531e9d946 | ||
|
|
04328aeb97 | ||
|
|
d0d26d5064 | ||
|
|
8623dd8a72 | ||
|
|
8cd75cff9f | ||
|
|
8ab9d9ea88 | ||
|
|
6e42def14b | ||
|
|
c413480b35 | ||
|
|
8f25124269 | ||
|
|
790df757cb |
32
.github/workflows/base.yml
vendored
32
.github/workflows/base.yml
vendored
@@ -51,6 +51,14 @@ jobs:
|
|||||||
torch_cuda_arch_list: "7.0 7.5 8.0 8.6 8.7 8.9 9.0+PTX"
|
torch_cuda_arch_list: "7.0 7.5 8.0 8.6 8.7 8.9 9.0+PTX"
|
||||||
dockerfile: "Dockerfile-base"
|
dockerfile: "Dockerfile-base"
|
||||||
platforms: "linux/amd64,linux/arm64"
|
platforms: "linux/amd64,linux/arm64"
|
||||||
|
- cuda: "129"
|
||||||
|
cuda_version: 12.9.1
|
||||||
|
cudnn_version: ""
|
||||||
|
python_version: "3.12"
|
||||||
|
pytorch: 2.9.1
|
||||||
|
torch_cuda_arch_list: "7.0 7.5 8.0 8.6 8.7 8.9 9.0+PTX"
|
||||||
|
dockerfile: "Dockerfile-base"
|
||||||
|
platforms: "linux/amd64,linux/arm64"
|
||||||
- cuda: "130"
|
- cuda: "130"
|
||||||
cuda_version: 13.0.0
|
cuda_version: 13.0.0
|
||||||
cudnn_version: ""
|
cudnn_version: ""
|
||||||
@@ -59,6 +67,14 @@ jobs:
|
|||||||
torch_cuda_arch_list: "9.0+PTX"
|
torch_cuda_arch_list: "9.0+PTX"
|
||||||
dockerfile: "Dockerfile-base"
|
dockerfile: "Dockerfile-base"
|
||||||
platforms: "linux/amd64,linux/arm64"
|
platforms: "linux/amd64,linux/arm64"
|
||||||
|
- cuda: "130"
|
||||||
|
cuda_version: 13.0.0
|
||||||
|
cudnn_version: ""
|
||||||
|
python_version: "3.12"
|
||||||
|
pytorch: 2.9.1
|
||||||
|
torch_cuda_arch_list: "9.0+PTX"
|
||||||
|
dockerfile: "Dockerfile-base"
|
||||||
|
platforms: "linux/amd64,linux/arm64"
|
||||||
# - cuda: "128"
|
# - cuda: "128"
|
||||||
# cuda_version: 12.8.1
|
# cuda_version: 12.8.1
|
||||||
# cudnn_version: ""
|
# cudnn_version: ""
|
||||||
@@ -141,6 +157,14 @@ jobs:
|
|||||||
torch_cuda_arch_list: "7.0 7.5 8.0 8.6 8.7 8.9 9.0+PTX"
|
torch_cuda_arch_list: "7.0 7.5 8.0 8.6 8.7 8.9 9.0+PTX"
|
||||||
dockerfile: "Dockerfile-uv-base"
|
dockerfile: "Dockerfile-uv-base"
|
||||||
platforms: "linux/amd64,linux/arm64"
|
platforms: "linux/amd64,linux/arm64"
|
||||||
|
- cuda: "129"
|
||||||
|
cuda_version: 12.9.1
|
||||||
|
cudnn_version: ""
|
||||||
|
python_version: "3.12"
|
||||||
|
pytorch: 2.9.1
|
||||||
|
torch_cuda_arch_list: "7.0 7.5 8.0 8.6 8.7 8.9 9.0+PTX"
|
||||||
|
dockerfile: "Dockerfile-uv-base"
|
||||||
|
platforms: "linux/amd64,linux/arm64"
|
||||||
- cuda: "130"
|
- cuda: "130"
|
||||||
cuda_version: 13.0.0
|
cuda_version: 13.0.0
|
||||||
cudnn_version: ""
|
cudnn_version: ""
|
||||||
@@ -149,6 +173,14 @@ jobs:
|
|||||||
torch_cuda_arch_list: "9.0+PTX"
|
torch_cuda_arch_list: "9.0+PTX"
|
||||||
dockerfile: "Dockerfile-uv-base"
|
dockerfile: "Dockerfile-uv-base"
|
||||||
platforms: "linux/amd64,linux/arm64"
|
platforms: "linux/amd64,linux/arm64"
|
||||||
|
- cuda: "130"
|
||||||
|
cuda_version: 13.0.0
|
||||||
|
cudnn_version: ""
|
||||||
|
python_version: "3.12"
|
||||||
|
pytorch: 2.9.1
|
||||||
|
torch_cuda_arch_list: "9.0+PTX"
|
||||||
|
dockerfile: "Dockerfile-uv-base"
|
||||||
|
platforms: "linux/amd64,linux/arm64"
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|||||||
12
.github/workflows/main.yml
vendored
12
.github/workflows/main.yml
vendored
@@ -34,6 +34,12 @@ jobs:
|
|||||||
axolotl_extras:
|
axolotl_extras:
|
||||||
platforms: "linux/amd64,linux/arm64"
|
platforms: "linux/amd64,linux/arm64"
|
||||||
is_latest: true
|
is_latest: true
|
||||||
|
- cuda: 129
|
||||||
|
cuda_version: 12.9.1
|
||||||
|
python_version: "3.12"
|
||||||
|
pytorch: 2.9.1
|
||||||
|
axolotl_extras:
|
||||||
|
platforms: "linux/amd64,linux/arm64"
|
||||||
- cuda: 130
|
- cuda: 130
|
||||||
cuda_version: 13.0.0
|
cuda_version: 13.0.0
|
||||||
python_version: "3.11"
|
python_version: "3.11"
|
||||||
@@ -106,6 +112,12 @@ jobs:
|
|||||||
axolotl_extras:
|
axolotl_extras:
|
||||||
is_latest: true
|
is_latest: true
|
||||||
platforms: "linux/amd64,linux/arm64"
|
platforms: "linux/amd64,linux/arm64"
|
||||||
|
- cuda: 129
|
||||||
|
cuda_version: 12.9.1
|
||||||
|
python_version: "3.12"
|
||||||
|
pytorch: 2.9.1
|
||||||
|
axolotl_extras:
|
||||||
|
platforms: "linux/amd64,linux/arm64"
|
||||||
- cuda: 130
|
- cuda: 130
|
||||||
cuda_version: 13.0.0
|
cuda_version: 13.0.0
|
||||||
python_version: "3.11"
|
python_version: "3.11"
|
||||||
|
|||||||
17
.github/workflows/multi-gpu-e2e.yml
vendored
17
.github/workflows/multi-gpu-e2e.yml
vendored
@@ -35,21 +35,26 @@ jobs:
|
|||||||
pytorch: 2.8.0
|
pytorch: 2.8.0
|
||||||
axolotl_extras: fbgemm-gpu
|
axolotl_extras: fbgemm-gpu
|
||||||
num_gpus: 2
|
num_gpus: 2
|
||||||
nightly_build: "true"
|
|
||||||
- cuda: 128
|
- cuda: 128
|
||||||
cuda_version: 12.8.1
|
cuda_version: 12.8.1
|
||||||
python_version: "3.11"
|
python_version: "3.11"
|
||||||
pytorch: 2.9.1
|
pytorch: 2.9.1
|
||||||
axolotl_extras: fbgemm-gpu
|
axolotl_extras: "fbgemm-gpu"
|
||||||
num_gpus: 2
|
num_gpus: 2
|
||||||
nightly_build: "true"
|
- cuda: 129
|
||||||
|
cuda_version: 12.9.1
|
||||||
|
python_version: "3.12"
|
||||||
|
pytorch: 2.9.1
|
||||||
|
axolotl_extras: "fbgemm-gpu"
|
||||||
|
num_gpus: 2
|
||||||
|
dockerfile: "Dockerfile-uv.jinja"
|
||||||
- cuda: 130
|
- cuda: 130
|
||||||
cuda_version: 13.0.0
|
cuda_version: 13.0.0
|
||||||
python_version: "3.11"
|
python_version: "3.11"
|
||||||
pytorch: 2.9.1
|
pytorch: 2.9.1
|
||||||
axolotl_extras: fbgemm-gpu
|
axolotl_extras:
|
||||||
|
# axolotl_extras: fbgemm-gpu
|
||||||
num_gpus: 2
|
num_gpus: 2
|
||||||
nightly_build: "true"
|
|
||||||
runs-on: [self-hosted, modal]
|
runs-on: [self-hosted, modal]
|
||||||
timeout-minutes: 120
|
timeout-minutes: 120
|
||||||
steps:
|
steps:
|
||||||
@@ -71,8 +76,8 @@ jobs:
|
|||||||
echo "AXOLOTL_EXTRAS=${{ matrix.axolotl_extras}}" >> $GITHUB_ENV
|
echo "AXOLOTL_EXTRAS=${{ matrix.axolotl_extras}}" >> $GITHUB_ENV
|
||||||
echo "CUDA=${{ matrix.cuda }}" >> $GITHUB_ENV
|
echo "CUDA=${{ matrix.cuda }}" >> $GITHUB_ENV
|
||||||
echo "N_GPUS=${{ matrix.num_gpus }}" >> $GITHUB_ENV
|
echo "N_GPUS=${{ matrix.num_gpus }}" >> $GITHUB_ENV
|
||||||
echo "NIGHTLY_BUILD=${{ matrix.nightly_build }}" >> $GITHUB_ENV
|
|
||||||
echo "CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }}" >> $GITHUB_ENV
|
echo "CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }}" >> $GITHUB_ENV
|
||||||
|
echo "E2E_DOCKERFILE=${{ matrix.dockerfile || 'Dockerfile.jinja'}}" >> $GITHUB_ENV
|
||||||
- name: Run tests job on Modal
|
- name: Run tests job on Modal
|
||||||
run: |
|
run: |
|
||||||
modal run -m cicd.multigpu
|
modal run -m cicd.multigpu
|
||||||
|
|||||||
6
.github/workflows/pypi.yml
vendored
6
.github/workflows/pypi.yml
vendored
@@ -40,7 +40,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
pip3 install wheel packaging==23.2
|
pip3 install wheel packaging==26.0
|
||||||
pip3 install --no-build-isolation -e .
|
pip3 install --no-build-isolation -e .
|
||||||
pip3 install -r requirements-dev.txt -r requirements-tests.txt
|
pip3 install -r requirements-dev.txt -r requirements-tests.txt
|
||||||
|
|
||||||
@@ -48,9 +48,9 @@ jobs:
|
|||||||
id: tag
|
id: tag
|
||||||
run: echo ::set-output name=TAG_NAME::$(echo $GITHUB_REF | cut -d / -f 3)
|
run: echo ::set-output name=TAG_NAME::$(echo $GITHUB_REF | cut -d / -f 3)
|
||||||
|
|
||||||
- name: Update version in setup.py
|
- name: Update version in VERSION file
|
||||||
run: |
|
run: |
|
||||||
sed -i -E 's/version="([0-9.]+)",/version="${{ steps.tag.outputs.TAG_NAME }}",/g' setup.py
|
echo "${{ steps.tag.outputs.TAG_NAME }}" | sed 's/^v//' > VERSION
|
||||||
|
|
||||||
- name: Build a source dist
|
- name: Build a source dist
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
2
.github/workflows/tests-nightly.yml
vendored
2
.github/workflows/tests-nightly.yml
vendored
@@ -48,7 +48,7 @@ jobs:
|
|||||||
- name: upgrade pip
|
- name: upgrade pip
|
||||||
run: |
|
run: |
|
||||||
pip3 install --upgrade pip
|
pip3 install --upgrade pip
|
||||||
pip3 install --upgrade packaging==23.2 setuptools==75.8.0 wheel
|
pip3 install --upgrade packaging==26.0 setuptools==75.8.0 wheel
|
||||||
|
|
||||||
- name: Install PyTorch
|
- name: Install PyTorch
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
46
.github/workflows/tests.yml
vendored
46
.github/workflows/tests.yml
vendored
@@ -54,8 +54,13 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
python_version: ["3.11"]
|
python_version: ["3.11", "3.12"]
|
||||||
pytorch_version: ["2.8.0", "2.9.0", "2.9.1"]
|
pytorch_version: ["2.8.0", "2.9.0", "2.9.1"]
|
||||||
|
exclude:
|
||||||
|
- python_version: "3.12"
|
||||||
|
pytorch_version: "2.8.0"
|
||||||
|
- python_version: "3.12"
|
||||||
|
pytorch_version: "2.9.0"
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -82,7 +87,7 @@ jobs:
|
|||||||
- name: upgrade pip
|
- name: upgrade pip
|
||||||
run: |
|
run: |
|
||||||
pip3 install --upgrade pip
|
pip3 install --upgrade pip
|
||||||
pip3 install --upgrade packaging==23.2 setuptools==75.8.0 wheel
|
pip3 install --upgrade packaging==26.0 setuptools==75.8.0 wheel
|
||||||
|
|
||||||
- name: Install PyTorch
|
- name: Install PyTorch
|
||||||
run: |
|
run: |
|
||||||
@@ -110,10 +115,10 @@ jobs:
|
|||||||
|
|
||||||
- name: Pre-Download dataset fixture
|
- name: Pre-Download dataset fixture
|
||||||
run: |
|
run: |
|
||||||
huggingface-cli download --repo-type=dataset axolotl-ai-internal/axolotl-oss-dataset-fixtures
|
hf download --repo-type=dataset axolotl-ai-internal/axolotl-oss-dataset-fixtures
|
||||||
|
|
||||||
- name: Show HF cache
|
- name: Show HF cache
|
||||||
run: hf cache scan
|
run: hf cache ls
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: |
|
run: |
|
||||||
@@ -127,7 +132,7 @@ jobs:
|
|||||||
pytest -v --durations=10 tests/cli/ --cov=axolotl --cov-append --cov-report=xml
|
pytest -v --durations=10 tests/cli/ --cov=axolotl --cov-append --cov-report=xml
|
||||||
|
|
||||||
- name: Show HF cache
|
- name: Show HF cache
|
||||||
run: hf cache scan
|
run: hf cache ls
|
||||||
|
|
||||||
- name: Upload coverage to Codecov
|
- name: Upload coverage to Codecov
|
||||||
uses: codecov/codecov-action@v5
|
uses: codecov/codecov-action@v5
|
||||||
@@ -144,8 +149,13 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
python_version: ["3.11"]
|
python_version: ["3.11", "3.12"]
|
||||||
pytorch_version: ["2.8.0", "2.9.0", "2.9.1"]
|
pytorch_version: ["2.8.0", "2.9.0", "2.9.1"]
|
||||||
|
exclude:
|
||||||
|
- python_version: "3.12"
|
||||||
|
pytorch_version: "2.8.0"
|
||||||
|
- python_version: "3.12"
|
||||||
|
pytorch_version: "2.9.0"
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -172,7 +182,7 @@ jobs:
|
|||||||
- name: upgrade pip
|
- name: upgrade pip
|
||||||
run: |
|
run: |
|
||||||
pip3 install --upgrade pip
|
pip3 install --upgrade pip
|
||||||
pip3 install --upgrade packaging==23.2 setuptools==75.8.0 setuptools_scm build wheel psutil
|
pip3 install --upgrade packaging==26.0 setuptools==75.8.0 setuptools_scm build wheel psutil
|
||||||
|
|
||||||
- name: Install PyTorch
|
- name: Install PyTorch
|
||||||
run: |
|
run: |
|
||||||
@@ -200,7 +210,7 @@ jobs:
|
|||||||
axolotl --help
|
axolotl --help
|
||||||
|
|
||||||
- name: Show HF cache
|
- name: Show HF cache
|
||||||
run: hf cache scan
|
run: hf cache ls
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: |
|
run: |
|
||||||
@@ -209,10 +219,10 @@ jobs:
|
|||||||
pytest -v --durations=10 tests/cli/
|
pytest -v --durations=10 tests/cli/
|
||||||
|
|
||||||
- name: Show HF cache
|
- name: Show HF cache
|
||||||
run: hf cache scan
|
run: hf cache ls
|
||||||
|
|
||||||
gate-skip-e2e:
|
gate-skip-e2e:
|
||||||
needs: [pre-commit, pytest, pytest-sdist]
|
needs: [pre-commit]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
skip: ${{ steps.compute.outputs.skip }}
|
skip: ${{ steps.compute.outputs.skip }}
|
||||||
@@ -248,16 +258,16 @@ jobs:
|
|||||||
# this job needs to be run on self-hosted GPU runners...
|
# this job needs to be run on self-hosted GPU runners...
|
||||||
runs-on: [self-hosted, modal]
|
runs-on: [self-hosted, modal]
|
||||||
timeout-minutes: 120
|
timeout-minutes: 120
|
||||||
needs: [pre-commit, pytest, pytest-sdist, gate-skip-e2e]
|
needs: [pre-commit, pytest]
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- cuda: 128
|
- cuda: 129
|
||||||
cuda_version: 12.8.1
|
cuda_version: 12.9.1
|
||||||
python_version: "3.11"
|
python_version: "3.12"
|
||||||
pytorch: 2.8.0
|
pytorch: 2.9.1
|
||||||
num_gpus: 1
|
num_gpus: 1
|
||||||
axolotl_extras:
|
axolotl_extras:
|
||||||
dockerfile: "Dockerfile-uv.jinja"
|
dockerfile: "Dockerfile-uv.jinja"
|
||||||
@@ -359,9 +369,9 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- cuda: 128
|
- cuda: 129
|
||||||
cuda_version: 12.8.1
|
cuda_version: 12.9.1
|
||||||
python_version: "3.11"
|
python_version: "3.12"
|
||||||
pytorch: 2.9.1
|
pytorch: 2.9.1
|
||||||
num_gpus: 1
|
num_gpus: 1
|
||||||
axolotl_extras:
|
axolotl_extras:
|
||||||
|
|||||||
@@ -224,9 +224,6 @@
|
|||||||
# eval_table_size: # Approximate number of predictions sent to wandb depending on batch size. Enabled above 0. Default is 0
|
# eval_table_size: # Approximate number of predictions sent to wandb depending on batch size. Enabled above 0. Default is 0
|
||||||
# eval_table_max_new_tokens: # Total number of tokens generated for predictions sent to wandb. Default is 128
|
# eval_table_max_new_tokens: # Total number of tokens generated for predictions sent to wandb. Default is 128
|
||||||
|
|
||||||
# # Save model as safetensors (require safetensors package)
|
|
||||||
# save_safetensors:
|
|
||||||
|
|
||||||
# # Whether to mask out or include the human's prompt from the training labels
|
# # Whether to mask out or include the human's prompt from the training labels
|
||||||
# train_on_inputs: false
|
# train_on_inputs: false
|
||||||
# # Group similarly sized data to minimize padding.
|
# # Group similarly sized data to minimize padding.
|
||||||
@@ -512,7 +509,6 @@ profiler_steps: ${PROFILER_STEPS}
|
|||||||
loss_watchdog_threshold: ${LOSS_WATCHDOG_THRESHOLD}
|
loss_watchdog_threshold: ${LOSS_WATCHDOG_THRESHOLD}
|
||||||
loss_watchdog_patience: ${LOSS_WATCHDOG_PATIENCE}
|
loss_watchdog_patience: ${LOSS_WATCHDOG_PATIENCE}
|
||||||
|
|
||||||
save_safetensors: ${SAVE_SAFETENSORS}
|
|
||||||
train_on_inputs: ${TRAIN_ON_INPUTS}
|
train_on_inputs: ${TRAIN_ON_INPUTS}
|
||||||
group_by_length: ${GROUP_BY_LENGTH}
|
group_by_length: ${GROUP_BY_LENGTH}
|
||||||
gradient_checkpointing: ${GRADIENT_CHECKPOINTING}
|
gradient_checkpointing: ${GRADIENT_CHECKPOINTING}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ Features:
|
|||||||
#### Using pip
|
#### Using pip
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip3 install -U packaging==23.2 setuptools==75.8.0 wheel ninja
|
pip3 install -U packaging==26.0 setuptools==75.8.0 wheel ninja
|
||||||
pip3 install --no-build-isolation axolotl[flash-attn,deepspeed]
|
pip3 install --no-build-isolation axolotl[flash-attn,deepspeed]
|
||||||
|
|
||||||
# Download example axolotl configs, deepspeed configs
|
# Download example axolotl configs, deepspeed configs
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ RUN if [ "$NIGHTLY_BUILD" = "true" ] ; then \
|
|||||||
sed -i 's#^datasets.*#datasets @ git+https://github.com/huggingface/datasets.git@main#' requirements.txt; \
|
sed -i 's#^datasets.*#datasets @ git+https://github.com/huggingface/datasets.git@main#' requirements.txt; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RUN uv pip install packaging==23.2 setuptools==75.8.0
|
RUN uv pip install packaging==26.0 setuptools==75.8.0
|
||||||
RUN uv pip install torchvision
|
RUN uv pip install torchvision
|
||||||
RUN if [ "$AXOLOTL_EXTRAS" != "" ] ; then \
|
RUN if [ "$AXOLOTL_EXTRAS" != "" ] ; then \
|
||||||
uv pip install --no-build-isolation -e .[deepspeed,flash-attn,ring-flash-attn,optimizers,ray,$AXOLOTL_EXTRAS] $AXOLOTL_ARGS; \
|
uv pip install --no-build-isolation -e .[deepspeed,flash-attn,ring-flash-attn,optimizers,ray,$AXOLOTL_EXTRAS] $AXOLOTL_ARGS; \
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ RUN if [ "$NIGHTLY_BUILD" = "true" ] ; then \
|
|||||||
sed -i 's#^datasets.*#datasets @ git+https://github.com/huggingface/datasets.git@main#' requirements.txt; \
|
sed -i 's#^datasets.*#datasets @ git+https://github.com/huggingface/datasets.git@main#' requirements.txt; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RUN pip install packaging==23.2 setuptools==75.8.0 psutil
|
RUN pip install packaging==26.0 setuptools==75.8.0 psutil
|
||||||
RUN if [ "$AXOLOTL_EXTRAS" != "" ] ; then \
|
RUN if [ "$AXOLOTL_EXTRAS" != "" ] ; then \
|
||||||
pip install --no-build-isolation -e .[deepspeed,flash-attn,ring-flash-attn,optimizers,ray,$AXOLOTL_EXTRAS] $AXOLOTL_ARGS; \
|
pip install --no-build-isolation -e .[deepspeed,flash-attn,ring-flash-attn,optimizers,ray,$AXOLOTL_EXTRAS] $AXOLOTL_ARGS; \
|
||||||
else \
|
else \
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ template_loader = jinja2.FileSystemLoader(searchpath=cicd_path)
|
|||||||
template_env = jinja2.Environment(
|
template_env = jinja2.Environment(
|
||||||
loader=template_loader, autoescape=select_autoescape()
|
loader=template_loader, autoescape=select_autoescape()
|
||||||
)
|
)
|
||||||
df_template = template_env.get_template("Dockerfile.jinja")
|
dockerfile = os.environ.get("E2E_DOCKERFILE", "Dockerfile.jinja")
|
||||||
|
df_template = template_env.get_template(dockerfile)
|
||||||
|
|
||||||
df_args = {
|
df_args = {
|
||||||
"AXOLOTL_EXTRAS": os.environ.get("AXOLOTL_EXTRAS", ""),
|
"AXOLOTL_EXTRAS": os.environ.get("AXOLOTL_EXTRAS", ""),
|
||||||
@@ -27,8 +28,11 @@ df_args = {
|
|||||||
"CUDA": os.environ.get("CUDA", "126"),
|
"CUDA": os.environ.get("CUDA", "126"),
|
||||||
"GITHUB_REF": os.environ.get("GITHUB_REF", "refs/heads/main"),
|
"GITHUB_REF": os.environ.get("GITHUB_REF", "refs/heads/main"),
|
||||||
"GITHUB_SHA": os.environ.get("GITHUB_SHA", ""),
|
"GITHUB_SHA": os.environ.get("GITHUB_SHA", ""),
|
||||||
|
"NIGHTLY_BUILD": os.environ.get("NIGHTLY_BUILD", ""),
|
||||||
"CODECOV_TOKEN": os.environ.get("CODECOV_TOKEN", ""),
|
"CODECOV_TOKEN": os.environ.get("CODECOV_TOKEN", ""),
|
||||||
"HF_HOME": "/workspace/data/huggingface-cache/hub",
|
"HF_HOME": "/workspace/data/huggingface-cache/hub",
|
||||||
|
"PYTHONUNBUFFERED": os.environ.get("PYTHONUNBUFFERED", "1"),
|
||||||
|
"DEEPSPEED_LOG_LEVEL": os.environ.get("DEEPSPEED_LOG_LEVEL", "WARNING"),
|
||||||
}
|
}
|
||||||
|
|
||||||
dockerfile_contents = df_template.render(**df_args)
|
dockerfile_contents = df_template.render(**df_args)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Only run two tests at a time to avoid OOM on GPU (with coverage collection)
|
# Only run two tests at a time to avoid OOM on GPU (with coverage collection)
|
||||||
pytest -v --durations=10 -n2 --maxfail=4 \
|
pytest -v --durations=10 -n2 --maxfail=3 \
|
||||||
--ignore=/workspace/axolotl/tests/e2e/multigpu/solo/ \
|
--ignore=/workspace/axolotl/tests/e2e/multigpu/solo/ \
|
||||||
--ignore=/workspace/axolotl/tests/e2e/multigpu/patched/ \
|
--ignore=/workspace/axolotl/tests/e2e/multigpu/patched/ \
|
||||||
/workspace/axolotl/tests/e2e/multigpu/ \
|
/workspace/axolotl/tests/e2e/multigpu/ \
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ ENV PATH="/root/miniconda3/envs/py${PYTHON_VERSION}/bin:${PATH}"
|
|||||||
|
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
|
|
||||||
RUN python3 -m pip install --upgrade pip && pip3 install -U packaging==23.2 setuptools==75.8.0 wheel psutil && \
|
RUN python3 -m pip install --upgrade pip && pip3 install -U packaging==26.0 setuptools==75.8.0 wheel psutil && \
|
||||||
python3 -m pip install --no-cache-dir -U torch==${PYTORCH_VERSION}+cu${CUDA} torchvision --extra-index-url https://download.pytorch.org/whl/cu$CUDA && \
|
python3 -m pip install --no-cache-dir -U torch==${PYTORCH_VERSION}+cu${CUDA} torchvision --extra-index-url https://download.pytorch.org/whl/cu$CUDA && \
|
||||||
python3 -m pip cache purge
|
python3 -m pip cache purge
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ ENV PATH="/root/miniconda3/envs/py${PYTHON_VERSION}/bin:${PATH}"
|
|||||||
|
|
||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
|
|
||||||
RUN python3 -m pip install --upgrade pip && pip3 install -U packaging==23.2 setuptools==75.8.0 wheel && \
|
RUN python3 -m pip install --upgrade pip && pip3 install -U packaging==26.0 setuptools==75.8.0 wheel && \
|
||||||
python3 -m pip install --no-cache-dir -U torch --extra-index-url https://download.pytorch.org/whl/nightly/cu$CUDA && \
|
python3 -m pip install --no-cache-dir -U torch --extra-index-url https://download.pytorch.org/whl/nightly/cu$CUDA && \
|
||||||
python3 -m pip install --no-cache-dir "causal_conv1d @ git+https://github.com/Dao-AILab/causal-conv1d.git@main" && \
|
python3 -m pip install --no-cache-dir "causal_conv1d @ git+https://github.com/Dao-AILab/causal-conv1d.git@main" && \
|
||||||
python3 -m pip install --no-cache-dir "mamba_ssm @ git+https://github.com/state-spaces/mamba.git@main" && \
|
python3 -m pip install --no-cache-dir "mamba_ssm @ git+https://github.com/state-spaces/mamba.git@main" && \
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ export HF_DATASETS_OFFLINE=1
|
|||||||
Download a base model using the Hugging Face CLI:
|
Download a base model using the Hugging Face CLI:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
huggingface-cli download meta-llama/Meta-Llama-3.1-8B --local-dir ~/hfdata/llama3.1-8B
|
hf download meta-llama/Meta-Llama-3.1-8B --local-dir ~/hfdata/llama3.1-8B
|
||||||
```
|
```
|
||||||
|
|
||||||
### 10. Create Axolotl Configuration
|
### 10. Create Axolotl Configuration
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ We recommend using WSL2 (Windows Subsystem for Linux) or Docker.
|
|||||||
```
|
```
|
||||||
4. (Optional) Login to Hugging Face:
|
4. (Optional) Login to Hugging Face:
|
||||||
```{.bash}
|
```{.bash}
|
||||||
huggingface-cli login
|
hf auth login
|
||||||
```
|
```
|
||||||
|
|
||||||
## Troubleshooting {#sec-troubleshooting}
|
## Troubleshooting {#sec-troubleshooting}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ feedback. Various methods include, but not limited to:
|
|||||||
- [Kahneman-Tversky Optimization (KTO)](#kto)
|
- [Kahneman-Tversky Optimization (KTO)](#kto)
|
||||||
- [Odds Ratio Preference Optimization (ORPO)](#orpo)
|
- [Odds Ratio Preference Optimization (ORPO)](#orpo)
|
||||||
- [Group Relative Policy Optimization (GRPO)](#grpo)
|
- [Group Relative Policy Optimization (GRPO)](#grpo)
|
||||||
|
- [Group Reward-Decoupled Policy Optimization (GDPO)](#gdpo)
|
||||||
|
|
||||||
|
|
||||||
## RLHF using Axolotl
|
## RLHF using Axolotl
|
||||||
@@ -720,6 +721,102 @@ trl:
|
|||||||
|
|
||||||
For more information, see [GRPO docs](https://huggingface.co/docs/trl/v0.17.0/en/grpo_trainer#loss-types).
|
For more information, see [GRPO docs](https://huggingface.co/docs/trl/v0.17.0/en/grpo_trainer#loss-types).
|
||||||
|
|
||||||
|
### GDPO
|
||||||
|
|
||||||
|
GDPO (Group Reward-Decoupled Policy Optimization) extends GRPO for multi-reward training. It addresses the **reward advantage collapse** problem by normalizing each reward function independently before combining them.
|
||||||
|
|
||||||
|
::: {.callout-tip}
|
||||||
|
Use GDPO when training with multiple reward functions. For single reward, GRPO and GDPO produce equivalent results.
|
||||||
|
:::
|
||||||
|
|
||||||
|
Paper: [https://arxiv.org/pdf/2501.05242](https://arxiv.org/pdf/2501.05242)
|
||||||
|
|
||||||
|
GDPO uses TRL's native `multi_objective_aggregation` parameter under the hood. When you set `rl: gdpo`, axolotl automatically configures TRL to use `normalize_then_sum` aggregation.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
base_model: Qwen/Qwen2.5-1.5B-Instruct
|
||||||
|
|
||||||
|
vllm:
|
||||||
|
host: 0.0.0.0
|
||||||
|
port: 8000
|
||||||
|
tensor_parallel_size: 2
|
||||||
|
gpu_memory_utilization: 0.85
|
||||||
|
|
||||||
|
rl: gdpo
|
||||||
|
|
||||||
|
trl:
|
||||||
|
beta: 0.001
|
||||||
|
max_completion_length: 256
|
||||||
|
use_vllm: true
|
||||||
|
num_generations: 4
|
||||||
|
reward_funcs:
|
||||||
|
- rewards.format_reward
|
||||||
|
- rewards.correctness_reward
|
||||||
|
reward_weights: [1.0, 2.0]
|
||||||
|
|
||||||
|
datasets:
|
||||||
|
- path: openai/gsm8k
|
||||||
|
name: main
|
||||||
|
type: rewards.oai_gsm8k_transform
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use GRPO with explicit aggregation control:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
rl: grpo
|
||||||
|
trl:
|
||||||
|
multi_objective_aggregation: normalize_then_sum # GDPO behavior
|
||||||
|
# or: sum_then_normalize # Default GRPO behavior
|
||||||
|
```
|
||||||
|
|
||||||
|
#### GDPO vs GRPO
|
||||||
|
|
||||||
|
| Aspect | GRPO | GDPO |
|
||||||
|
|--------|------|------|
|
||||||
|
| **Aggregation** | `sum_then_normalize` | `normalize_then_sum` |
|
||||||
|
| **Multi-reward** | May collapse advantages | Preserves reward signals |
|
||||||
|
| **Single reward** | Standard behavior | Equivalent to GRPO |
|
||||||
|
|
||||||
|
#### Why GDPO?
|
||||||
|
|
||||||
|
When using multiple rewards with GRPO, different reward combinations can produce identical advantages:
|
||||||
|
|
||||||
|
```
|
||||||
|
# Example: format + correctness rewards
|
||||||
|
[format=0, correct=3] → sum=3
|
||||||
|
[format=1, correct=2] → sum=3 ← GRPO sees these as equal!
|
||||||
|
[format=2, correct=1] → sum=3
|
||||||
|
[format=3, correct=0] → sum=3
|
||||||
|
```
|
||||||
|
|
||||||
|
GDPO normalizes each reward independently, preserving their relative differences.
|
||||||
|
|
||||||
|
#### Reward Functions
|
||||||
|
|
||||||
|
GDPO uses the same reward function format as GRPO:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# rewards.py
|
||||||
|
def format_reward(completions, **kwargs) -> list[float]:
|
||||||
|
return [1.0 if len(c) > 10 else 0.0 for c in completions]
|
||||||
|
|
||||||
|
def correctness_reward(completions, answers, **kwargs) -> list[float]:
|
||||||
|
rewards = []
|
||||||
|
for completion, answer in zip(completions, answers):
|
||||||
|
# Your scoring logic here
|
||||||
|
rewards.append(score)
|
||||||
|
return rewards
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Sequence Parallelism
|
||||||
|
|
||||||
|
GDPO supports sequence parallelism for long-context training:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
rl: gdpo
|
||||||
|
context_parallel_size: 2
|
||||||
|
```
|
||||||
|
|
||||||
### SimPO
|
### SimPO
|
||||||
|
|
||||||
SimPO uses [CPOTrainer](https://huggingface.co/docs/trl/main/en/cpo_trainer) but with alternative loss function.
|
SimPO uses [CPOTrainer](https://huggingface.co/docs/trl/main/en/cpo_trainer) but with alternative loss function.
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ This guide shows how to fine-tune it with Axolotl with multi-turn conversations
|
|||||||
git clone https://github.com/axolotl-ai-cloud/axolotl.git
|
git clone https://github.com/axolotl-ai-cloud/axolotl.git
|
||||||
cd axolotl
|
cd axolotl
|
||||||
|
|
||||||
pip3 install packaging==23.2 setuptools==75.8.0 wheel ninja
|
pip3 install packaging==26.0 setuptools==75.8.0 wheel ninja
|
||||||
pip3 install --no-build-isolation -e '.[flash-attn]'
|
pip3 install --no-build-isolation -e '.[flash-attn]'
|
||||||
|
|
||||||
# Install CCE https://docs.axolotl.ai/docs/custom_integrations.html#cut-cross-entropy
|
# Install CCE https://docs.axolotl.ai/docs/custom_integrations.html#cut-cross-entropy
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ Thanks to the team at Arcee.ai for using Axolotl in supervised fine-tuning the A
|
|||||||
git clone https://github.com/axolotl-ai-cloud/axolotl.git
|
git clone https://github.com/axolotl-ai-cloud/axolotl.git
|
||||||
cd axolotl
|
cd axolotl
|
||||||
|
|
||||||
pip3 install packaging==23.2 setuptools==75.8.0 wheel ninja
|
pip3 install packaging==26.0 setuptools==75.8.0 wheel ninja
|
||||||
pip3 install --no-build-isolation -e '.[flash-attn]'
|
pip3 install --no-build-isolation -e '.[flash-attn]'
|
||||||
|
|
||||||
# Install CCE https://docs.axolotl.ai/docs/custom_integrations.html#cut-cross-entropy
|
# Install CCE https://docs.axolotl.ai/docs/custom_integrations.html#cut-cross-entropy
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
"%%capture\n",
|
"%%capture\n",
|
||||||
"# This step can take ~5-10 minutes to install dependencies\n",
|
"# This step can take ~5-10 minutes to install dependencies\n",
|
||||||
"!pip install --no-build-isolation axolotl[flash-attn]>=0.9.1\n",
|
"!pip install --no-build-isolation axolotl[flash-attn]>=0.9.1\n",
|
||||||
"!pip install \"cut-cross-entropy[transformers] @ git+https://github.com/axolotl-ai-cloud/ml-cross-entropy.git@318b7e2\""
|
"!pip install \"cut-cross-entropy[transformers] @ git+https://github.com/axolotl-ai-cloud/ml-cross-entropy.git@f4b5712\""
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ Thanks to the team at MistralAI for giving us early access to prepare for this r
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Ensure you have Pytorch installed (Pytorch 2.6.0 min)
|
# Ensure you have Pytorch installed (Pytorch 2.6.0 min)
|
||||||
pip3 install packaging==23.2 setuptools==75.8.0 wheel ninja
|
pip3 install packaging==26.0 setuptools==75.8.0 wheel ninja
|
||||||
pip3 install --no-build-isolation 'axolotl[flash-attn]>=0.12.0'
|
pip3 install --no-build-isolation 'axolotl[flash-attn]>=0.12.0'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
77
examples/eaft/eaft-example.yml
Normal file
77
examples/eaft/eaft-example.yml
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
base_model: google/gemma-3-1b-it
|
||||||
|
|
||||||
|
model_type: Gemma3ForCausalLM
|
||||||
|
cls_model_config: Gemma3TextConfig
|
||||||
|
|
||||||
|
# gemma3 doesn't seem to play nice with ddp
|
||||||
|
ddp_find_unused_parameters: true
|
||||||
|
|
||||||
|
chat_template: gemma3
|
||||||
|
eot_tokens:
|
||||||
|
- <end_of_turn>
|
||||||
|
|
||||||
|
load_in_8bit: false
|
||||||
|
load_in_4bit: false
|
||||||
|
strict: false
|
||||||
|
|
||||||
|
datasets:
|
||||||
|
- path: cgato/SlimOrcaDedupCleaned
|
||||||
|
type: chat_template
|
||||||
|
field_messages: conversations
|
||||||
|
message_property_mappings:
|
||||||
|
role: from
|
||||||
|
content: value
|
||||||
|
|
||||||
|
dataset_prepared_path:
|
||||||
|
val_set_size: 0
|
||||||
|
output_dir: ./outputs/eaft-gemma-3-1b
|
||||||
|
|
||||||
|
use_eaft: true
|
||||||
|
eaft_alpha: 1.0
|
||||||
|
eaft_k: 20
|
||||||
|
|
||||||
|
sequence_len: 1024
|
||||||
|
sample_packing: false
|
||||||
|
|
||||||
|
adapter:
|
||||||
|
lora_model_dir:
|
||||||
|
|
||||||
|
wandb_project:
|
||||||
|
wandb_entity:
|
||||||
|
wandb_watch:
|
||||||
|
wandb_name:
|
||||||
|
wandb_log_model:
|
||||||
|
|
||||||
|
gradient_accumulation_steps: 4
|
||||||
|
micro_batch_size: 1
|
||||||
|
eval_batch_size: 1
|
||||||
|
max_steps: 1000
|
||||||
|
evaluation_strategy: "no"
|
||||||
|
optimizer: adamw_torch_fused
|
||||||
|
lr_scheduler: cosine
|
||||||
|
learning_rate: 5e-5
|
||||||
|
|
||||||
|
train_on_inputs: false
|
||||||
|
group_by_length: false
|
||||||
|
bf16: auto
|
||||||
|
fp16:
|
||||||
|
tf32: true
|
||||||
|
|
||||||
|
gradient_checkpointing: true
|
||||||
|
gradient_checkpointing_kwargs:
|
||||||
|
use_reentrant: false
|
||||||
|
|
||||||
|
early_stopping_patience:
|
||||||
|
resume_from_checkpoint:
|
||||||
|
local_rank:
|
||||||
|
logging_steps: 1
|
||||||
|
xformers_attention:
|
||||||
|
flash_attention: true
|
||||||
|
|
||||||
|
warmup_ratio: 0.1
|
||||||
|
weight_decay: 0.0
|
||||||
|
debug:
|
||||||
|
deepspeed:
|
||||||
|
fsdp:
|
||||||
|
fsdp_config:
|
||||||
|
special_tokens:
|
||||||
@@ -10,7 +10,7 @@ Gemma-3n is a family of multimodal models from Google found on [HuggingFace](htt
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Ensure you have Pytorch installed (Pytorch 2.6.0 min)
|
# Ensure you have Pytorch installed (Pytorch 2.6.0 min)
|
||||||
pip3 install packaging==23.2 setuptools==75.8.0 wheel ninja
|
pip3 install packaging==26.0 setuptools==75.8.0 wheel ninja
|
||||||
pip3 install --no-build-isolation 'axolotl[flash-attn]>=0.12.0'
|
pip3 install --no-build-isolation 'axolotl[flash-attn]>=0.12.0'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ This guide shows how to fine-tune it with Axolotl with multi-turn conversations
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Ensure you have Pytorch installed (Pytorch 2.6.0 min)
|
# Ensure you have Pytorch installed (Pytorch 2.6.0 min)
|
||||||
pip3 install packaging==23.2 setuptools==75.8.0 wheel ninja
|
pip3 install packaging==26.0 setuptools==75.8.0 wheel ninja
|
||||||
pip3 install --no-build-isolation 'axolotl[flash-attn]>=0.12.0'
|
pip3 install --no-build-isolation 'axolotl[flash-attn]>=0.12.0'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ This guide shows how to fine-tune it with Axolotl with multi-turn conversations
|
|||||||
git clone https://github.com/axolotl-ai-cloud/axolotl.git
|
git clone https://github.com/axolotl-ai-cloud/axolotl.git
|
||||||
cd axolotl
|
cd axolotl
|
||||||
|
|
||||||
pip3 install packaging==23.2 setuptools==75.8.0 wheel ninja
|
pip3 install packaging==26.0 setuptools==75.8.0 wheel ninja
|
||||||
pip3 install --no-build-isolation -e '.[flash-attn]'
|
pip3 install --no-build-isolation -e '.[flash-attn]'
|
||||||
|
|
||||||
# Install CCE https://docs.axolotl.ai/docs/custom_integrations.html#cut-cross-entropy
|
# Install CCE https://docs.axolotl.ai/docs/custom_integrations.html#cut-cross-entropy
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ Tencent released a family of opensource models called HunYuan with varying param
|
|||||||
git clone https://github.com/axolotl-ai-cloud/axolotl.git
|
git clone https://github.com/axolotl-ai-cloud/axolotl.git
|
||||||
cd axolotl
|
cd axolotl
|
||||||
|
|
||||||
pip3 install packaging==23.2 setuptools==75.8.0 wheel ninja
|
pip3 install packaging==26.0 setuptools==75.8.0 wheel ninja
|
||||||
pip3 install --no-build-isolation -e '.[flash-attn]'
|
pip3 install --no-build-isolation -e '.[flash-attn]'
|
||||||
|
|
||||||
# Install CCE https://docs.axolotl.ai/docs/custom_integrations.html#cut-cross-entropy
|
# Install CCE https://docs.axolotl.ai/docs/custom_integrations.html#cut-cross-entropy
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ datasets:
|
|||||||
dataset_prepared_path: last_run_prepared
|
dataset_prepared_path: last_run_prepared
|
||||||
val_set_size: 0.0
|
val_set_size: 0.0
|
||||||
output_dir: jamba-large-fsdp-qlora-ft
|
output_dir: jamba-large-fsdp-qlora-ft
|
||||||
save_safetensors: true
|
|
||||||
adapter: qlora
|
adapter: qlora
|
||||||
sequence_len: 2048
|
sequence_len: 2048
|
||||||
sample_packing: true
|
sample_packing: true
|
||||||
|
|||||||
68
examples/llama-3/qlora-1b-gdpo.yaml
Normal file
68
examples/llama-3/qlora-1b-gdpo.yaml
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
base_model: meta-llama/Llama-3.2-1B-Instruct
|
||||||
|
|
||||||
|
chat_template: llama3
|
||||||
|
|
||||||
|
rl: gdpo
|
||||||
|
|
||||||
|
trl:
|
||||||
|
beta: 0.001
|
||||||
|
max_completion_length: 128
|
||||||
|
num_generations: 2
|
||||||
|
temperature: 0.7
|
||||||
|
top_p: 0.95
|
||||||
|
|
||||||
|
use_vllm: false
|
||||||
|
|
||||||
|
|
||||||
|
multi_objective_aggregation: normalize_then_sum
|
||||||
|
|
||||||
|
reward_funcs:
|
||||||
|
- rwd.format_reward
|
||||||
|
- rwd.correctness_reward
|
||||||
|
reward_weights: [1.0, 2.0]
|
||||||
|
|
||||||
|
log_completions: true
|
||||||
|
num_completions_to_print: 3
|
||||||
|
scale_rewards: true
|
||||||
|
|
||||||
|
datasets:
|
||||||
|
- path: openai/gsm8k
|
||||||
|
name: main
|
||||||
|
split: train[:1000]
|
||||||
|
type: rwd.gsm8k_transform
|
||||||
|
|
||||||
|
val_set_size: 0.0
|
||||||
|
output_dir: ./outputs/llama3-gdpo-out
|
||||||
|
|
||||||
|
sequence_len: 512
|
||||||
|
sample_packing: false
|
||||||
|
pad_to_sequence_len: false
|
||||||
|
|
||||||
|
gradient_accumulation_steps: 8
|
||||||
|
micro_batch_size: 1
|
||||||
|
num_epochs: 1
|
||||||
|
max_steps: 100
|
||||||
|
|
||||||
|
optimizer: adamw_torch_fused
|
||||||
|
lr_scheduler: cosine
|
||||||
|
learning_rate: 5e-5
|
||||||
|
weight_decay: 0.01
|
||||||
|
warmup_steps: 10
|
||||||
|
|
||||||
|
bf16: auto
|
||||||
|
tf32: true
|
||||||
|
|
||||||
|
gradient_checkpointing: true
|
||||||
|
gradient_checkpointing_kwargs:
|
||||||
|
use_reentrant: false
|
||||||
|
|
||||||
|
flash_attention: true
|
||||||
|
logging_steps: 1
|
||||||
|
save_steps: 50
|
||||||
|
save_safetensors: true
|
||||||
|
|
||||||
|
special_tokens:
|
||||||
|
pad_token: "<|end_of_text|>"
|
||||||
|
|
||||||
|
|
||||||
|
seed: 42
|
||||||
@@ -12,7 +12,6 @@ datasets:
|
|||||||
dataset_prepared_path: last_run_prepared
|
dataset_prepared_path: last_run_prepared
|
||||||
val_set_size: 0.0
|
val_set_size: 0.0
|
||||||
output_dir: ./outputs/out/qlora-llama3_1-405b
|
output_dir: ./outputs/out/qlora-llama3_1-405b
|
||||||
save_safetensors: true
|
|
||||||
|
|
||||||
adapter: qlora
|
adapter: qlora
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Thanks to the team at MistralAI for giving us early access to prepare for these
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Ensure you have Pytorch installed (Pytorch 2.7.0 min)
|
# Ensure you have Pytorch installed (Pytorch 2.7.0 min)
|
||||||
pip3 install packaging==23.2 setuptools==75.8.0 wheel ninja
|
pip3 install packaging==26.0 setuptools==75.8.0 wheel ninja
|
||||||
pip3 install --no-build-isolation 'axolotl[flash-attn]>=0.12.0'
|
pip3 install --no-build-isolation 'axolotl[flash-attn]>=0.12.0'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,5 @@ saves_per_epoch: 1
|
|||||||
weight_decay: 0.0
|
weight_decay: 0.0
|
||||||
special_tokens:
|
special_tokens:
|
||||||
tokens:
|
tokens:
|
||||||
save_safetensors: False
|
|
||||||
|
|
||||||
# save_first_step: true # uncomment this to validate checkpoint saving works with your config
|
# save_first_step: true # uncomment this to validate checkpoint saving works with your config
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ This guide shows how to fine-tune it with Axolotl with multi-turn conversations
|
|||||||
git clone https://github.com/axolotl-ai-cloud/axolotl.git
|
git clone https://github.com/axolotl-ai-cloud/axolotl.git
|
||||||
cd axolotl
|
cd axolotl
|
||||||
|
|
||||||
pip3 install packaging==23.2 setuptools==75.8.0 wheel ninja
|
pip3 install packaging==26.0 setuptools==75.8.0 wheel ninja
|
||||||
pip3 install --no-build-isolation -e '.[flash-attn]'
|
pip3 install --no-build-isolation -e '.[flash-attn]'
|
||||||
|
|
||||||
# Install CCE https://docs.axolotl.ai/docs/custom_integrations.html#cut-cross-entropy
|
# Install CCE https://docs.axolotl.ai/docs/custom_integrations.html#cut-cross-entropy
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ Thanks to the team at MistralAI for giving us early access to prepare for this r
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Ensure you have Pytorch installed (Pytorch 2.6.0 min)
|
# Ensure you have Pytorch installed (Pytorch 2.6.0 min)
|
||||||
pip3 install packaging==23.2 setuptools==75.8.0 wheel ninja
|
pip3 install packaging==26.0 setuptools==75.8.0 wheel ninja
|
||||||
pip3 install --no-build-isolation 'axolotl[flash-attn]>=0.12.0'
|
pip3 install --no-build-isolation 'axolotl[flash-attn]>=0.12.0'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[build-system]
|
[build-system]
|
||||||
requires = ["setuptools>=64", "wheel", "setuptools_scm>=8", "packaging==23.2"]
|
requires = ["setuptools>=64", "wheel", "setuptools_scm>=8", "packaging==26.0"]
|
||||||
build-backend = "setuptools.build_meta"
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
@@ -24,6 +24,9 @@ Repository = "https://github.com/axolotl-ai-cloud/axolotl.git"
|
|||||||
py-modules = ["setuptools_axolotl_dynamic_dependencies"]
|
py-modules = ["setuptools_axolotl_dynamic_dependencies"]
|
||||||
include-package-data = true
|
include-package-data = true
|
||||||
|
|
||||||
|
[tool.setuptools.dynamic]
|
||||||
|
version = { file = "VERSION" }
|
||||||
|
|
||||||
[tool.setuptools.cmdclass]
|
[tool.setuptools.cmdclass]
|
||||||
build_py = "setuptools_axolotl_dynamic_dependencies.BuildPyCommand"
|
build_py = "setuptools_axolotl_dynamic_dependencies.BuildPyCommand"
|
||||||
|
|
||||||
@@ -57,3 +60,6 @@ indent-style = "space"
|
|||||||
skip-magic-trailing-comma = false
|
skip-magic-trailing-comma = false
|
||||||
line-ending = "auto"
|
line-ending = "auto"
|
||||||
docstring-code-format = false
|
docstring-code-format = false
|
||||||
|
|
||||||
|
[tool.uv.extra-build-dependencies]
|
||||||
|
axolotl = ["huggingface_hub"]
|
||||||
|
|||||||
@@ -8,18 +8,18 @@ xformers>=0.0.23.post1
|
|||||||
liger-kernel==0.6.4
|
liger-kernel==0.6.4
|
||||||
# END section
|
# END section
|
||||||
|
|
||||||
packaging==23.2
|
packaging==26.0
|
||||||
|
huggingface_hub>=1.1.7
|
||||||
huggingface_hub>=0.36.0
|
peft>=0.18.1
|
||||||
peft>=0.18.0
|
|
||||||
tokenizers>=0.22.1
|
tokenizers>=0.22.1
|
||||||
transformers==4.57.1
|
transformers==5.0.0
|
||||||
accelerate==1.12.0
|
accelerate==1.12.0
|
||||||
datasets==4.4.2
|
datasets==4.5.0
|
||||||
deepspeed>=0.18.3
|
deepspeed>=0.18.3
|
||||||
trl==0.25.1
|
trl==0.27.1
|
||||||
hf_xet==1.2.0
|
hf_xet==1.2.0
|
||||||
kernels==0.11.5
|
kernels==0.11.5
|
||||||
|
|
||||||
trackio>=0.13.0
|
trackio>=0.13.0
|
||||||
typing-extensions>=4.15.0
|
typing-extensions>=4.15.0
|
||||||
|
|
||||||
@@ -72,4 +72,4 @@ axolotl-contribs-mit==0.0.6
|
|||||||
# telemetry
|
# telemetry
|
||||||
posthog==6.7.11
|
posthog==6.7.11
|
||||||
|
|
||||||
mistral-common==1.8.6
|
mistral-common==1.8.8
|
||||||
|
|||||||
@@ -29,5 +29,5 @@ UV_PREFIX = "uv " if USE_UV else ""
|
|||||||
|
|
||||||
print(
|
print(
|
||||||
UNINSTALL_PREFIX
|
UNINSTALL_PREFIX
|
||||||
+ f'{UV_PREFIX}pip install "cut-cross-entropy[transformers] @ git+https://github.com/axolotl-ai-cloud/ml-cross-entropy.git@318b7e2"'
|
+ f'{UV_PREFIX}pip install "cut-cross-entropy[transformers] @ git+https://github.com/axolotl-ai-cloud/ml-cross-entropy.git@f4b5712"'
|
||||||
)
|
)
|
||||||
|
|||||||
62
setup.py
62
setup.py
@@ -1,6 +1,5 @@
|
|||||||
"""setup.py for axolotl"""
|
"""setup.py for axolotl"""
|
||||||
|
|
||||||
import ast
|
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
@@ -26,6 +25,7 @@ def parse_requirements(extras_require_map):
|
|||||||
_install_requires.append(line)
|
_install_requires.append(line)
|
||||||
try:
|
try:
|
||||||
xformers_version = [req for req in _install_requires if "xformers" in req][0]
|
xformers_version = [req for req in _install_requires if "xformers" in req][0]
|
||||||
|
install_xformers = platform.machine() != "aarch64"
|
||||||
if "Darwin" in platform.system():
|
if "Darwin" in platform.system():
|
||||||
# skip packages not compatible with OSX
|
# skip packages not compatible with OSX
|
||||||
skip_packages = [
|
skip_packages = [
|
||||||
@@ -62,44 +62,68 @@ def parse_requirements(extras_require_map):
|
|||||||
else:
|
else:
|
||||||
raise ValueError("Invalid version format")
|
raise ValueError("Invalid version format")
|
||||||
|
|
||||||
|
torch_parts = torch_version.split("+")
|
||||||
|
if len(torch_parts) == 2:
|
||||||
|
torch_cuda_version = torch_parts[1]
|
||||||
|
_dependency_links.append(
|
||||||
|
f"https://download.pytorch.org/whl/{torch_cuda_version}"
|
||||||
|
)
|
||||||
|
|
||||||
if (major, minor) >= (2, 9):
|
if (major, minor) >= (2, 9):
|
||||||
extras_require_map.pop("fbgemm-gpu")
|
extras_require_map.pop("fbgemm-gpu")
|
||||||
extras_require_map["fbgemm-gpu"] = ["fbgemm-gpu-genai==1.4.1"]
|
extras_require_map["fbgemm-gpu"] = [
|
||||||
|
"fbgemm-gpu==1.4.0",
|
||||||
|
"fbgemm-gpu-genai==1.4.2",
|
||||||
|
]
|
||||||
extras_require_map["vllm"] = ["vllm==0.11.1"]
|
extras_require_map["vllm"] = ["vllm==0.11.1"]
|
||||||
|
if not install_xformers:
|
||||||
|
_install_requires.pop(_install_requires.index(xformers_version))
|
||||||
|
extras_require_map["vllm"] = ["vllm==0.13.0"]
|
||||||
|
if patch == 0:
|
||||||
|
extras_require_map["vllm"] = ["vllm==0.13.0"]
|
||||||
|
else:
|
||||||
|
extras_require_map["vllm"] = ["vllm==0.14.0"]
|
||||||
elif (major, minor) >= (2, 8):
|
elif (major, minor) >= (2, 8):
|
||||||
extras_require_map.pop("fbgemm-gpu")
|
extras_require_map.pop("fbgemm-gpu")
|
||||||
extras_require_map["fbgemm-gpu"] = ["fbgemm-gpu-genai==1.3.0"]
|
extras_require_map["fbgemm-gpu"] = ["fbgemm-gpu-genai==1.3.0"]
|
||||||
extras_require_map["vllm"] = ["vllm==0.11.0"]
|
extras_require_map["vllm"] = ["vllm==0.11.0"]
|
||||||
|
if not install_xformers:
|
||||||
|
_install_requires.pop(_install_requires.index(xformers_version))
|
||||||
elif (major, minor) >= (2, 7):
|
elif (major, minor) >= (2, 7):
|
||||||
_install_requires.pop(_install_requires.index(xformers_version))
|
_install_requires.pop(_install_requires.index(xformers_version))
|
||||||
if patch == 0:
|
if patch == 0:
|
||||||
_install_requires.append("xformers==0.0.30")
|
if install_xformers:
|
||||||
|
_install_requires.append("xformers==0.0.30")
|
||||||
# vllm 0.9.x is incompatible with latest transformers
|
# vllm 0.9.x is incompatible with latest transformers
|
||||||
extras_require_map.pop("vllm")
|
extras_require_map.pop("vllm")
|
||||||
else:
|
else:
|
||||||
_install_requires.append("xformers==0.0.31")
|
if install_xformers:
|
||||||
|
_install_requires.append("xformers==0.0.31")
|
||||||
extras_require_map["vllm"] = ["vllm==0.10.1"]
|
extras_require_map["vllm"] = ["vllm==0.10.1"]
|
||||||
elif (major, minor) >= (2, 6):
|
elif (major, minor) >= (2, 6):
|
||||||
_install_requires.pop(_install_requires.index(xformers_version))
|
_install_requires.pop(_install_requires.index(xformers_version))
|
||||||
_install_requires.append("xformers==0.0.29.post3")
|
if install_xformers:
|
||||||
|
_install_requires.append("xformers==0.0.29.post3")
|
||||||
# since we only support 2.6.0+cu126
|
# since we only support 2.6.0+cu126
|
||||||
_dependency_links.append("https://download.pytorch.org/whl/cu126")
|
_dependency_links.append("https://download.pytorch.org/whl/cu126")
|
||||||
extras_require_map.pop("vllm")
|
extras_require_map.pop("vllm")
|
||||||
elif (major, minor) >= (2, 5):
|
elif (major, minor) >= (2, 5):
|
||||||
_install_requires.pop(_install_requires.index(xformers_version))
|
_install_requires.pop(_install_requires.index(xformers_version))
|
||||||
if patch == 0:
|
if install_xformers:
|
||||||
_install_requires.append("xformers==0.0.28.post2")
|
if patch == 0:
|
||||||
else:
|
_install_requires.append("xformers==0.0.28.post2")
|
||||||
_install_requires.append("xformers>=0.0.28.post3")
|
else:
|
||||||
|
_install_requires.append("xformers>=0.0.28.post3")
|
||||||
extras_require_map.pop("vllm")
|
extras_require_map.pop("vllm")
|
||||||
elif (major, minor) >= (2, 4):
|
elif (major, minor) >= (2, 4):
|
||||||
extras_require_map.pop("vllm")
|
extras_require_map.pop("vllm")
|
||||||
if patch == 0:
|
if install_xformers:
|
||||||
_install_requires.pop(_install_requires.index(xformers_version))
|
if patch == 0:
|
||||||
_install_requires.append("xformers>=0.0.27")
|
_install_requires.pop(_install_requires.index(xformers_version))
|
||||||
else:
|
_install_requires.append("xformers>=0.0.27")
|
||||||
_install_requires.pop(_install_requires.index(xformers_version))
|
else:
|
||||||
_install_requires.append("xformers==0.0.28.post1")
|
_install_requires.pop(_install_requires.index(xformers_version))
|
||||||
|
_install_requires.append("xformers==0.0.28.post1")
|
||||||
else:
|
else:
|
||||||
raise ValueError("axolotl requires torch>=2.4")
|
raise ValueError("axolotl requires torch>=2.4")
|
||||||
|
|
||||||
@@ -110,15 +134,11 @@ def parse_requirements(extras_require_map):
|
|||||||
|
|
||||||
def get_package_version():
|
def get_package_version():
|
||||||
with open(
|
with open(
|
||||||
Path(os.path.dirname(os.path.abspath(__file__)))
|
Path(os.path.dirname(os.path.abspath(__file__))) / "VERSION",
|
||||||
/ "src"
|
|
||||||
/ "axolotl"
|
|
||||||
/ "__init__.py",
|
|
||||||
"r",
|
"r",
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
) as fin:
|
) as fin:
|
||||||
version_match = re.search(r"^__version__\s*=\s*(.*)$", fin.read(), re.MULTILINE)
|
version_ = fin.read().strip()
|
||||||
version_ = ast.literal_eval(version_match.group(1))
|
|
||||||
return version_
|
return version_
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
"""Axolotl - Train and fine-tune large language models"""
|
"""Axolotl - Train and fine-tune large language models"""
|
||||||
|
|
||||||
import pkgutil
|
import pkgutil
|
||||||
|
from importlib.metadata import PackageNotFoundError, version
|
||||||
|
|
||||||
__path__ = pkgutil.extend_path(__path__, __name__) # Make this a namespace package
|
__path__ = pkgutil.extend_path(__path__, __name__) # Make this a namespace package
|
||||||
|
|
||||||
__version__ = "0.13.0.dev"
|
try:
|
||||||
|
__version__ = version("axolotl")
|
||||||
|
except PackageNotFoundError:
|
||||||
|
__version__ = "unknown"
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ import os
|
|||||||
from axolotl.logging_config import configure_logging
|
from axolotl.logging_config import configure_logging
|
||||||
|
|
||||||
os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
|
os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
|
||||||
os.environ.setdefault("HF_HUB_ENABLE_HF_TRANSFER", "1")
|
os.environ.setdefault("HF_XET_HIGH_PERFORMANCE", "1")
|
||||||
|
|
||||||
configure_logging()
|
configure_logging()
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ def check_user_token() -> bool:
|
|||||||
return bool(user_info)
|
return bool(user_info)
|
||||||
except LocalTokenNotFoundError:
|
except LocalTokenNotFoundError:
|
||||||
LOG.warning(
|
LOG.warning(
|
||||||
"Error verifying HuggingFace token. Remember to log in using `huggingface-cli login` and get your access token from https://huggingface.co/settings/tokens if you want to use gated models or datasets."
|
"Error verifying HuggingFace token. Remember to log in using `hf auth login` and get your access token from https://huggingface.co/settings/tokens if you want to use gated models or datasets."
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ def do_merge_lora(*, cfg: DictDefault) -> None:
|
|||||||
cfg: Dictionary mapping `axolotl` config keys to values.
|
cfg: Dictionary mapping `axolotl` config keys to values.
|
||||||
"""
|
"""
|
||||||
model, tokenizer, processor = load_model_and_tokenizer(cfg=cfg)
|
model, tokenizer, processor = load_model_and_tokenizer(cfg=cfg)
|
||||||
safe_serialization = cfg.save_safetensors is True
|
|
||||||
|
|
||||||
LOG.info("Running merge of LoRA with base model...")
|
LOG.info("Running merge of LoRA with base model...")
|
||||||
model = model.merge_and_unload(progressbar=True)
|
model = model.merge_and_unload(progressbar=True)
|
||||||
@@ -42,7 +41,6 @@ def do_merge_lora(*, cfg: DictDefault) -> None:
|
|||||||
LOG.info(f"Saving merged model to: {str(Path(cfg.output_dir) / 'merged')}...")
|
LOG.info(f"Saving merged model to: {str(Path(cfg.output_dir) / 'merged')}...")
|
||||||
model.save_pretrained(
|
model.save_pretrained(
|
||||||
str(Path(cfg.output_dir) / "merged"),
|
str(Path(cfg.output_dir) / "merged"),
|
||||||
safe_serialization=safe_serialization,
|
|
||||||
progressbar=True,
|
progressbar=True,
|
||||||
)
|
)
|
||||||
tokenizer.save_pretrained(
|
tokenizer.save_pretrained(
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ from accelerate import PartialState
|
|||||||
from accelerate.utils import (
|
from accelerate.utils import (
|
||||||
SAFE_WEIGHTS_INDEX_NAME,
|
SAFE_WEIGHTS_INDEX_NAME,
|
||||||
SAFE_WEIGHTS_NAME,
|
SAFE_WEIGHTS_NAME,
|
||||||
WEIGHTS_INDEX_NAME,
|
|
||||||
WEIGHTS_NAME,
|
|
||||||
is_torch_version,
|
is_torch_version,
|
||||||
)
|
)
|
||||||
from huggingface_hub import split_torch_state_dict_into_shards
|
from huggingface_hub import split_torch_state_dict_into_shards
|
||||||
@@ -40,17 +38,15 @@ class BFloat16CastPlanner(_EmptyStateDictLoadPlanner):
|
|||||||
def _distributed_checkpoint_to_merged_weights(
|
def _distributed_checkpoint_to_merged_weights(
|
||||||
checkpoint_dir: Union[str, Path],
|
checkpoint_dir: Union[str, Path],
|
||||||
save_path: str,
|
save_path: str,
|
||||||
safe_serialization: bool = False,
|
|
||||||
max_shard_size: str = "5GB",
|
max_shard_size: str = "5GB",
|
||||||
) -> Path:
|
) -> Path:
|
||||||
"""
|
"""
|
||||||
Passthrough to `torch.distributed.checkpoint.format_utils.dcp_to_torch_save`. Will
|
Passthrough to `torch.distributed.checkpoint.format_utils.dcp_to_torch_save`. Will
|
||||||
save under `save_path` as either `model.safetensors` or `pytorch_model.bin`.
|
save under `save_path` as `model.safetensors`.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
checkpoint_dir: Directory where distributed checkpoint is saved.
|
checkpoint_dir: Directory where distributed checkpoint is saved.
|
||||||
save_path: Path to save model to.
|
save_path: Path to save model to.
|
||||||
safe_serialization: Whether to save in safetensors format.
|
|
||||||
max_shard_size: Max size of model shards to save.
|
max_shard_size: Max size of model shards to save.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@@ -76,11 +72,7 @@ def _distributed_checkpoint_to_merged_weights(
|
|||||||
if isinstance(value, torch.Tensor) and value.dtype != torch.bfloat16:
|
if isinstance(value, torch.Tensor) and value.dtype != torch.bfloat16:
|
||||||
state_dict[key] = value.to(torch.bfloat16)
|
state_dict[key] = value.to(torch.bfloat16)
|
||||||
|
|
||||||
weights_name = SAFE_WEIGHTS_NAME if safe_serialization else WEIGHTS_NAME
|
filename_pattern = SAFE_WEIGHTS_NAME.replace(".safetensors", "{suffix}.safetensors")
|
||||||
|
|
||||||
filename_pattern = weights_name.replace(".bin", "{suffix}.bin").replace(
|
|
||||||
".safetensors", "{suffix}.safetensors"
|
|
||||||
)
|
|
||||||
state_dict_split = split_torch_state_dict_into_shards(
|
state_dict_split = split_torch_state_dict_into_shards(
|
||||||
state_dict, filename_pattern=filename_pattern, max_shard_size=max_shard_size
|
state_dict, filename_pattern=filename_pattern, max_shard_size=max_shard_size
|
||||||
)
|
)
|
||||||
@@ -98,19 +90,12 @@ def _distributed_checkpoint_to_merged_weights(
|
|||||||
|
|
||||||
for shard_file, tensors in filename_to_tensors:
|
for shard_file, tensors in filename_to_tensors:
|
||||||
shard = {tensor: state_dict[tensor] for tensor in tensors}
|
shard = {tensor: state_dict[tensor] for tensor in tensors}
|
||||||
|
safe_save_file(
|
||||||
if safe_serialization:
|
shard, os.path.join(save_path_, shard_file), metadata={"format": "pt"}
|
||||||
safe_save_file(
|
)
|
||||||
shard, os.path.join(save_path_, shard_file), metadata={"format": "pt"}
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
torch.save(shard, os.path.join(save_path_, shard_file))
|
|
||||||
|
|
||||||
if index is not None:
|
if index is not None:
|
||||||
save_index_file = (
|
save_index_file = os.path.join(save_path_, SAFE_WEIGHTS_INDEX_NAME)
|
||||||
SAFE_WEIGHTS_INDEX_NAME if safe_serialization else WEIGHTS_INDEX_NAME
|
|
||||||
)
|
|
||||||
save_index_file = os.path.join(save_path_, save_index_file)
|
|
||||||
# Save the index as well
|
# Save the index as well
|
||||||
with open(save_index_file, "w", encoding="utf-8") as fout:
|
with open(save_index_file, "w", encoding="utf-8") as fout:
|
||||||
content = json.dumps(index, indent=2, sort_keys=True) + "\n"
|
content = json.dumps(index, indent=2, sort_keys=True) + "\n"
|
||||||
@@ -123,13 +108,11 @@ def _distributed_checkpoint_to_merged_weights(
|
|||||||
def merge_fsdp_weights(
|
def merge_fsdp_weights(
|
||||||
checkpoint_dir: str,
|
checkpoint_dir: str,
|
||||||
output_path: str,
|
output_path: str,
|
||||||
safe_serialization: bool = False,
|
|
||||||
remove_checkpoint_dir: bool = False,
|
remove_checkpoint_dir: bool = False,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Merge the weights from sharded FSDP model checkpoints into a single combined checkpoint. Should be used if
|
Merge the weights from sharded FSDP model checkpoints into a single combined checkpoint. Should be used if
|
||||||
`SHARDED_STATE_DICT` was used for the model. Weights will be saved to `{output_path}/model.safetensors` if
|
`SHARDED_STATE_DICT` was used for the model. Weights will be saved to `{output_path}/model.safetensors`.
|
||||||
`safe_serialization` else `pytorch_model.bin`.
|
|
||||||
|
|
||||||
Note: this is a CPU-bound process.
|
Note: this is a CPU-bound process.
|
||||||
|
|
||||||
@@ -138,8 +121,6 @@ def merge_fsdp_weights(
|
|||||||
The directory containing the FSDP checkpoints (can be either the model or optimizer).
|
The directory containing the FSDP checkpoints (can be either the model or optimizer).
|
||||||
output_path (`str`):
|
output_path (`str`):
|
||||||
The path to save the merged checkpoint.
|
The path to save the merged checkpoint.
|
||||||
safe_serialization (`bool`, *optional*, defaults to `True`):
|
|
||||||
Whether to save the merged weights with safetensors (recommended).
|
|
||||||
remove_checkpoint_dir (`bool`, *optional*, defaults to `False`):
|
remove_checkpoint_dir (`bool`, *optional*, defaults to `False`):
|
||||||
Whether to remove the checkpoint directory after merging.
|
Whether to remove the checkpoint directory after merging.
|
||||||
|
|
||||||
@@ -177,7 +158,7 @@ def merge_fsdp_weights(
|
|||||||
if state.is_main_process:
|
if state.is_main_process:
|
||||||
LOG.info(f"Merging FSDP weights from {checkpoint_dir_}")
|
LOG.info(f"Merging FSDP weights from {checkpoint_dir_}")
|
||||||
save_path = _distributed_checkpoint_to_merged_weights(
|
save_path = _distributed_checkpoint_to_merged_weights(
|
||||||
checkpoint_dir_, output_path, safe_serialization
|
checkpoint_dir_, output_path
|
||||||
)
|
)
|
||||||
LOG.info(f"Successfully merged FSDP weights and saved to {save_path}")
|
LOG.info(f"Successfully merged FSDP weights and saved to {save_path}")
|
||||||
if remove_checkpoint_dir:
|
if remove_checkpoint_dir:
|
||||||
@@ -210,7 +191,6 @@ def do_cli(config: Union[Path, str] = Path("examples/"), **kwargs):
|
|||||||
merge_fsdp_weights(
|
merge_fsdp_weights(
|
||||||
checkpoint_dir=str(fsdp_dir),
|
checkpoint_dir=str(fsdp_dir),
|
||||||
output_path=output_path,
|
output_path=output_path,
|
||||||
safe_serialization=True,
|
|
||||||
)
|
)
|
||||||
state = PartialState()
|
state = PartialState()
|
||||||
state.wait_for_everyone()
|
state.wait_for_everyone()
|
||||||
|
|||||||
@@ -102,12 +102,10 @@ def do_quantize(
|
|||||||
LOG.info(f"Saving quantized model to: {str(Path(output_dir) / 'quantized')}.")
|
LOG.info(f"Saving quantized model to: {str(Path(output_dir) / 'quantized')}.")
|
||||||
model.save_pretrained(
|
model.save_pretrained(
|
||||||
str(Path(output_dir) / "quantized"),
|
str(Path(output_dir) / "quantized"),
|
||||||
safe_serialization=False,
|
|
||||||
progressbar=True,
|
progressbar=True,
|
||||||
)
|
)
|
||||||
tokenizer.save_pretrained(
|
tokenizer.save_pretrained(
|
||||||
str(Path(output_dir) / "quantized"),
|
str(Path(output_dir) / "quantized"),
|
||||||
safe_serialization=False,
|
|
||||||
progressbar=True,
|
progressbar=True,
|
||||||
save_jinja_files=cfg.tokenizer_save_jinja_files,
|
save_jinja_files=cfg.tokenizer_save_jinja_files,
|
||||||
)
|
)
|
||||||
@@ -121,7 +119,7 @@ def do_quantize(
|
|||||||
hub_model_id.rstrip("-")
|
hub_model_id.rstrip("-")
|
||||||
+ f"-{quantization_config_to_str[type(quantization_config)]}"
|
+ f"-{quantization_config_to_str[type(quantization_config)]}"
|
||||||
)
|
)
|
||||||
model.push_to_hub(hub_model_id, safe_serialization=False)
|
model.push_to_hub(hub_model_id)
|
||||||
tokenizer.push_to_hub(hub_model_id)
|
tokenizer.push_to_hub(hub_model_id)
|
||||||
if processor:
|
if processor:
|
||||||
processor.push_to_hub(hub_model_id)
|
processor.push_to_hub(hub_model_id)
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ class TrainerBuilderBase(abc.ABC):
|
|||||||
def _configure_warmup_and_logging(
|
def _configure_warmup_and_logging(
|
||||||
self, total_num_steps: int, training_args_kwargs: dict
|
self, total_num_steps: int, training_args_kwargs: dict
|
||||||
):
|
):
|
||||||
warmup_steps = 0
|
warmup_steps: int | float = 0
|
||||||
warmup_ratio = 0.0
|
warmup_ratio = 0.0
|
||||||
if self.cfg.warmup_steps is not None:
|
if self.cfg.warmup_steps is not None:
|
||||||
warmup_steps = self.cfg.warmup_steps
|
warmup_steps = self.cfg.warmup_steps
|
||||||
@@ -230,6 +230,10 @@ class TrainerBuilderBase(abc.ABC):
|
|||||||
else:
|
else:
|
||||||
warmup_ratio = 0.03
|
warmup_ratio = 0.03
|
||||||
|
|
||||||
|
# transformers v5
|
||||||
|
if warmup_ratio > 0.0 and warmup_steps == 0:
|
||||||
|
warmup_steps = warmup_ratio
|
||||||
|
|
||||||
if warmup_steps == 1:
|
if warmup_steps == 1:
|
||||||
warmup_steps = 2
|
warmup_steps = 2
|
||||||
|
|
||||||
@@ -242,7 +246,6 @@ class TrainerBuilderBase(abc.ABC):
|
|||||||
else max(min(int(0.005 * total_num_steps), 10), 1)
|
else max(min(int(0.005 * total_num_steps), 10), 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
training_args_kwargs["warmup_ratio"] = warmup_ratio
|
|
||||||
training_args_kwargs["warmup_steps"] = warmup_steps
|
training_args_kwargs["warmup_steps"] = warmup_steps
|
||||||
|
|
||||||
def _configure_precision_settings(self, training_args_kwargs: dict):
|
def _configure_precision_settings(self, training_args_kwargs: dict):
|
||||||
@@ -530,9 +533,7 @@ class TrainerBuilderBase(abc.ABC):
|
|||||||
"loraplus_lr_ratio",
|
"loraplus_lr_ratio",
|
||||||
"loraplus_lr_embedding",
|
"loraplus_lr_embedding",
|
||||||
"output_dir",
|
"output_dir",
|
||||||
"save_safetensors",
|
|
||||||
"save_only_model",
|
"save_only_model",
|
||||||
"include_tokens_per_second",
|
|
||||||
"weight_decay",
|
"weight_decay",
|
||||||
"seed",
|
"seed",
|
||||||
"dion_momentum",
|
"dion_momentum",
|
||||||
@@ -545,6 +546,7 @@ class TrainerBuilderBase(abc.ABC):
|
|||||||
|
|
||||||
arg_map = {
|
arg_map = {
|
||||||
"dion_learning_rate": "dion_lr",
|
"dion_learning_rate": "dion_lr",
|
||||||
|
"include_num_input_tokens_seen": "include_tokens_per_second",
|
||||||
}
|
}
|
||||||
for kwarg, cfg_arg in arg_map.items():
|
for kwarg, cfg_arg in arg_map.items():
|
||||||
if hasattr(self.cfg, cfg_arg) and getattr(self.cfg, cfg_arg) is not None:
|
if hasattr(self.cfg, cfg_arg) and getattr(self.cfg, cfg_arg) is not None:
|
||||||
|
|||||||
@@ -373,6 +373,18 @@ class HFCausalTrainerBuilder(TrainerBuilderBase):
|
|||||||
# https://docs.nvidia.com/deeplearning/performance/dl-performance-matrix-multiplication/index.html
|
# https://docs.nvidia.com/deeplearning/performance/dl-performance-matrix-multiplication/index.html
|
||||||
data_collator_kwargs["pad_to_multiple_of"] = multiple
|
data_collator_kwargs["pad_to_multiple_of"] = multiple
|
||||||
|
|
||||||
|
if self.cfg.use_eaft:
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
from axolotl.monkeypatch.loss.eaft import eaft_loss
|
||||||
|
|
||||||
|
configured_eaft_loss = partial(
|
||||||
|
eaft_loss,
|
||||||
|
alpha=self.cfg.eaft_alpha if self.cfg.eaft_alpha is not None else 1.0,
|
||||||
|
k=self.cfg.eaft_k if self.cfg.eaft_k is not None else 20,
|
||||||
|
)
|
||||||
|
trainer_kwargs["compute_loss_func"] = configured_eaft_loss
|
||||||
|
|
||||||
trainer_cls = self._get_trainer_cls()
|
trainer_cls = self._get_trainer_cls()
|
||||||
|
|
||||||
trainer_kwargs, trainer_cls = self.hook_pre_create_trainer(
|
trainer_kwargs, trainer_cls = self.hook_pre_create_trainer(
|
||||||
@@ -437,7 +449,9 @@ class HFCausalTrainerBuilder(TrainerBuilderBase):
|
|||||||
or self.cfg.micro_batch_size > 1
|
or self.cfg.micro_batch_size > 1
|
||||||
):
|
):
|
||||||
return DataCollatorForSeq2Seq(self.tokenizer, **kwargs)
|
return DataCollatorForSeq2Seq(self.tokenizer, **kwargs)
|
||||||
if not (self.cfg.sample_packing and self.cfg.pretrain_multipack_attn):
|
if not (self.cfg.sample_packing and self.cfg.pretrain_multipack_attn) or (
|
||||||
|
self.cfg.micro_batch_size == 1 and is_eval is False
|
||||||
|
):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if self.cfg.model_config_type == "mamba":
|
if self.cfg.model_config_type == "mamba":
|
||||||
|
|||||||
@@ -52,12 +52,11 @@ class HFRLTrainerBuilder(TrainerBuilderBase):
|
|||||||
trainer_cls = None
|
trainer_cls = None
|
||||||
trainer_cls_args = [self.model]
|
trainer_cls_args = [self.model]
|
||||||
|
|
||||||
if self.cfg.rl is RLType.GRPO:
|
if self.cfg.rl in {RLType.GRPO, RLType.GDPO}:
|
||||||
trainer_cls = GRPOStrategy.get_trainer_class(
|
trainer_cls = GRPOStrategy.get_trainer_class(
|
||||||
sequence_parallel=self.cfg.context_parallel_size > 1
|
sequence_parallel=self.cfg.context_parallel_size > 1
|
||||||
)
|
)
|
||||||
trainer_cls_args.extend(GRPOStrategy.set_trainer_args(self.cfg))
|
trainer_cls_args.extend(GRPOStrategy.set_trainer_args(self.cfg))
|
||||||
|
|
||||||
trainer_kwargs.update(GRPOStrategy.set_trainer_kwargs(self.cfg))
|
trainer_kwargs.update(GRPOStrategy.set_trainer_kwargs(self.cfg))
|
||||||
|
|
||||||
elif self.cfg.rl in [RLType.DPO, RLType.IPO]:
|
elif self.cfg.rl in [RLType.DPO, RLType.IPO]:
|
||||||
@@ -147,6 +146,8 @@ class HFRLTrainerBuilder(TrainerBuilderBase):
|
|||||||
|
|
||||||
elif self.cfg.rl is RLType.KTO:
|
elif self.cfg.rl is RLType.KTO:
|
||||||
training_args_cls = AxolotlKTOConfig
|
training_args_cls = AxolotlKTOConfig
|
||||||
|
# KTOConfig in TRL >= 0.27.0 no longer accepts max_prompt_length
|
||||||
|
blocklist_args_kwargs = ["max_prompt_length"]
|
||||||
|
|
||||||
training_args_kwargs["desirable_weight"] = (
|
training_args_kwargs["desirable_weight"] = (
|
||||||
self.cfg.kto_desirable_weight or 1.0
|
self.cfg.kto_desirable_weight or 1.0
|
||||||
@@ -155,10 +156,14 @@ class HFRLTrainerBuilder(TrainerBuilderBase):
|
|||||||
self.cfg.kto_undesirable_weight or 1.0
|
self.cfg.kto_undesirable_weight or 1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
elif self.cfg.rl is RLType.GRPO:
|
elif self.cfg.rl in {RLType.GRPO, RLType.GDPO}:
|
||||||
training_args_cls = GRPOStrategy.get_training_args_class()
|
training_args_cls = GRPOStrategy.get_training_args_class()
|
||||||
training_args_kwargs.update(GRPOStrategy.set_training_args_kwargs(self.cfg))
|
training_args_kwargs.update(GRPOStrategy.set_training_args_kwargs(self.cfg))
|
||||||
blocklist_args_kwargs = GRPOStrategy.get_blocklist_args_kwargs()
|
blocklist_args_kwargs = GRPOStrategy.get_blocklist_args_kwargs()
|
||||||
|
if self.cfg.rl is RLType.GDPO:
|
||||||
|
training_args_kwargs.setdefault(
|
||||||
|
"multi_objective_aggregation", "normalize_then_sum"
|
||||||
|
)
|
||||||
|
|
||||||
elif self.cfg.rl in [RLType.DPO, RLType.IPO]:
|
elif self.cfg.rl in [RLType.DPO, RLType.IPO]:
|
||||||
training_args_cls = AxolotlDPOConfig
|
training_args_cls = AxolotlDPOConfig
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ from torch.utils.data import (
|
|||||||
from transformers import PreTrainedModel, Trainer
|
from transformers import PreTrainedModel, Trainer
|
||||||
from transformers.trainer import TRAINING_ARGS_NAME
|
from transformers.trainer import TRAINING_ARGS_NAME
|
||||||
from transformers.trainer_utils import PREFIX_CHECKPOINT_DIR, has_length, seed_worker
|
from transformers.trainer_utils import PREFIX_CHECKPOINT_DIR, has_length, seed_worker
|
||||||
from transformers.utils import SAFE_WEIGHTS_NAME, WEIGHTS_NAME, is_peft_available
|
from transformers.utils import SAFE_WEIGHTS_NAME, is_peft_available
|
||||||
from trl.trainer.utils import pad_to_length
|
from trl.trainer.utils import pad_to_length
|
||||||
from typing_extensions import override
|
from typing_extensions import override
|
||||||
|
|
||||||
@@ -738,43 +738,38 @@ class AxolotlTrainer(
|
|||||||
).save_pretrained(
|
).save_pretrained(
|
||||||
output_dir,
|
output_dir,
|
||||||
state_dict=state_dict,
|
state_dict=state_dict,
|
||||||
safe_serialization=self.args.save_safetensors,
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
LOG.info(
|
LOG.info(
|
||||||
"Trainer.model is not a `PreTrainedModel`, only saving its state dict."
|
"Trainer.model is not a `PreTrainedModel`, only saving its state dict."
|
||||||
)
|
)
|
||||||
if self.args.save_safetensors:
|
safetensors.torch.save_file(
|
||||||
safetensors.torch.save_file(
|
state_dict,
|
||||||
state_dict,
|
os.path.join(output_dir, SAFE_WEIGHTS_NAME),
|
||||||
os.path.join(output_dir, SAFE_WEIGHTS_NAME),
|
metadata={"format": "pt"},
|
||||||
metadata={"format": "pt"},
|
)
|
||||||
)
|
|
||||||
else:
|
|
||||||
torch.save(state_dict, os.path.join(output_dir, WEIGHTS_NAME))
|
|
||||||
else:
|
else:
|
||||||
self.model.save_pretrained(
|
self.model.save_pretrained(
|
||||||
output_dir,
|
output_dir,
|
||||||
state_dict=state_dict,
|
state_dict=state_dict,
|
||||||
safe_serialization=self.args.save_safetensors,
|
|
||||||
is_main_process=self.accelerator.is_main_process,
|
is_main_process=self.accelerator.is_main_process,
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.processing_class is not None:
|
if self.processing_class is not None:
|
||||||
self.processing_class.save_pretrained(output_dir)
|
self.processing_class.save_pretrained(output_dir)
|
||||||
elif (
|
elif (
|
||||||
self.data_collator is not None
|
self.data_collator is not None
|
||||||
and hasattr(self.data_collator, "tokenizer")
|
and hasattr(self.data_collator, "tokenizer")
|
||||||
and self.data_collator.tokenizer is not None
|
and self.data_collator.tokenizer is not None
|
||||||
):
|
):
|
||||||
LOG.info(
|
LOG.info(
|
||||||
"Saving Trainer.data_collator.tokenizer by default as Trainer.processing_class is `None`"
|
"Saving Trainer.data_collator.tokenizer by default as Trainer.processing_class is `None`"
|
||||||
)
|
)
|
||||||
save_jinja_files = True
|
save_jinja_files = True
|
||||||
if self.axolotl_cfg:
|
if self.axolotl_cfg:
|
||||||
save_jinja_files = self.axolotl_cfg.tokenizer_save_jinja_files
|
save_jinja_files = self.axolotl_cfg.tokenizer_save_jinja_files
|
||||||
self.data_collator.tokenizer.save_pretrained(
|
self.data_collator.tokenizer.save_pretrained(
|
||||||
output_dir, save_jinja_files=save_jinja_files
|
output_dir, save_jinja_files=save_jinja_files
|
||||||
)
|
)
|
||||||
# Good practice: save your training arguments together with the trained model
|
# Good practice: save your training arguments together with the trained model
|
||||||
torch.save(self.args, os.path.join(output_dir, TRAINING_ARGS_NAME))
|
torch.save(self.args, os.path.join(output_dir, TRAINING_ARGS_NAME))
|
||||||
|
|||||||
@@ -129,6 +129,11 @@ class GRPOStrategy:
|
|||||||
if trl.rollout_func:
|
if trl.rollout_func:
|
||||||
grpo_args_kwargs["rollout_func"] = cls.get_rollout_func(trl.rollout_func)
|
grpo_args_kwargs["rollout_func"] = cls.get_rollout_func(trl.rollout_func)
|
||||||
|
|
||||||
|
if trl.multi_objective_aggregation is not None:
|
||||||
|
grpo_args_kwargs["multi_objective_aggregation"] = (
|
||||||
|
trl.multi_objective_aggregation
|
||||||
|
)
|
||||||
|
|
||||||
return grpo_args_kwargs
|
return grpo_args_kwargs
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
"""Module for TRL RL trainers"""
|
"""Module for TRL RL trainers"""
|
||||||
|
|
||||||
from trl import (
|
from trl import RewardTrainer
|
||||||
CPOTrainer,
|
from trl.experimental.cpo import CPOTrainer
|
||||||
KTOTrainer,
|
from trl.experimental.kto import KTOTrainer
|
||||||
ORPOTrainer,
|
from trl.experimental.orpo import ORPOTrainer
|
||||||
PRMTrainer,
|
from trl.experimental.prm import PRMTrainer
|
||||||
RewardTrainer,
|
|
||||||
)
|
|
||||||
|
|
||||||
from axolotl.core.trainers.mixins import DistributedParallelMixin, RngLoaderMixin
|
from axolotl.core.trainers.mixins import DistributedParallelMixin, RngLoaderMixin
|
||||||
from axolotl.core.trainers.mixins.optimizer import OptimizerInitMixin, OptimizerMixin
|
from axolotl.core.trainers.mixins.optimizer import OptimizerInitMixin, OptimizerMixin
|
||||||
|
|||||||
@@ -8,7 +8,11 @@ from dataclasses import dataclass, field
|
|||||||
from typing import Optional, Type
|
from typing import Optional, Type
|
||||||
|
|
||||||
from transformers import TrainingArguments
|
from transformers import TrainingArguments
|
||||||
from trl import CPOConfig, KTOConfig, ORPOConfig, PRMConfig, RewardConfig
|
from trl import RewardConfig
|
||||||
|
from trl.experimental.cpo import CPOConfig
|
||||||
|
from trl.experimental.kto import KTOConfig
|
||||||
|
from trl.experimental.orpo import ORPOConfig
|
||||||
|
from trl.experimental.prm import PRMConfig
|
||||||
|
|
||||||
from axolotl.integrations.config import merge_training_args
|
from axolotl.integrations.config import merge_training_args
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ python scripts/cutcrossentropy_install.py | sh
|
|||||||
|
|
||||||
- If you are installing from pip
|
- If you are installing from pip
|
||||||
```bash
|
```bash
|
||||||
pip3 uninstall -y cut-cross-entropy && pip3 install "cut-cross-entropy[transformers] @ git+https://github.com/axolotl-ai-cloud/ml-cross-entropy.git@318b7e2"
|
pip3 uninstall -y cut-cross-entropy && pip3 install "cut-cross-entropy[transformers] @ git+https://github.com/axolotl-ai-cloud/ml-cross-entropy.git@f4b5712"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@@ -36,6 +36,7 @@ plugins:
|
|||||||
- cohere
|
- cohere
|
||||||
- cohere2
|
- cohere2
|
||||||
- deepseek_v3
|
- deepseek_v3
|
||||||
|
- exaone4
|
||||||
- gemma
|
- gemma
|
||||||
- gemma2
|
- gemma2
|
||||||
- gemma3
|
- gemma3
|
||||||
@@ -45,8 +46,11 @@ plugins:
|
|||||||
- glm
|
- glm
|
||||||
- glm4
|
- glm4
|
||||||
- glm4_moe
|
- glm4_moe
|
||||||
|
- glm4_moe_lite
|
||||||
|
- glm46v
|
||||||
- glm4v
|
- glm4v
|
||||||
- glm4v_moe
|
- glm4v_moe
|
||||||
|
- glm_image
|
||||||
- gpt_oss
|
- gpt_oss
|
||||||
- granite
|
- granite
|
||||||
- granitemoe
|
- granitemoe
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ LOG = get_logger(__name__)
|
|||||||
|
|
||||||
_CCE_INSTALL_MESSAGE = (
|
_CCE_INSTALL_MESSAGE = (
|
||||||
"Please install Axolotl's fork of cut_cross_entropy with transformers support using "
|
"Please install Axolotl's fork of cut_cross_entropy with transformers support using "
|
||||||
'`pip install "cut-cross-entropy[transformers] @ git+https://github.com/axolotl-ai-cloud/ml-cross-entropy.git@318b7e2"`'
|
'`pip install "cut-cross-entropy[transformers] @ git+https://github.com/axolotl-ai-cloud/ml-cross-entropy.git@f4b5712"`'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
7
src/axolotl/integrations/kernels/__init__.py
Normal file
7
src/axolotl/integrations/kernels/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from .args import KernelsArgs
|
||||||
|
from .plugin import KernelsPlugin
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"KernelsArgs",
|
||||||
|
"KernelsPlugin",
|
||||||
|
]
|
||||||
35
src/axolotl/integrations/kernels/args.py
Normal file
35
src/axolotl/integrations/kernels/args.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
from pydantic import BaseModel, model_validator
|
||||||
|
|
||||||
|
from axolotl.utils.logging import get_logger
|
||||||
|
|
||||||
|
LOG = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class KernelsArgs(BaseModel):
|
||||||
|
use_scattermoe: bool | None = True
|
||||||
|
|
||||||
|
@model_validator(mode="before")
|
||||||
|
@classmethod
|
||||||
|
def check_use_kernels(cls, data):
|
||||||
|
if data.get("use_kernels") is not True:
|
||||||
|
LOG.warning(
|
||||||
|
"`use_kernels` must be set to True to use this. Automatically setting it to True."
|
||||||
|
)
|
||||||
|
data["use_kernels"] = True
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
@model_validator(mode="before")
|
||||||
|
@classmethod
|
||||||
|
def check_experts_implementation(cls, data):
|
||||||
|
experts_implementation = data.get("experts_implementation")
|
||||||
|
if experts_implementation is None:
|
||||||
|
# transformers may default to batched_mm when unset
|
||||||
|
data["experts_implementation"] = "eager"
|
||||||
|
elif experts_implementation != "eager":
|
||||||
|
LOG.warning(
|
||||||
|
"`experts_implementation` must be set to 'eager' to use this. Automatically setting it to 'eager'."
|
||||||
|
)
|
||||||
|
data["experts_implementation"] = "eager"
|
||||||
|
|
||||||
|
return data
|
||||||
61
src/axolotl/integrations/kernels/plugin.py
Normal file
61
src/axolotl/integrations/kernels/plugin.py
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
from kernels import (
|
||||||
|
LayerRepository,
|
||||||
|
Mode,
|
||||||
|
register_kernel_mapping,
|
||||||
|
replace_kernel_forward_from_hub,
|
||||||
|
)
|
||||||
|
|
||||||
|
from axolotl.integrations.base import BasePlugin
|
||||||
|
from axolotl.utils.callbacks.models import get_causal_lm_model_cls_prefix
|
||||||
|
|
||||||
|
|
||||||
|
class KernelsPlugin(BasePlugin):
|
||||||
|
def get_input_args(self):
|
||||||
|
return "axolotl.integrations.kernels.KernelsArgs"
|
||||||
|
|
||||||
|
def pre_model_load(self, cfg):
|
||||||
|
if cfg.use_scattermoe:
|
||||||
|
self._register_kernels()
|
||||||
|
self._kernelize_model(cfg.model_config_type)
|
||||||
|
|
||||||
|
def _register_kernels(self):
|
||||||
|
register_kernel_mapping(
|
||||||
|
{
|
||||||
|
"HFScatterMoEParallelExperts": {
|
||||||
|
"cuda": {
|
||||||
|
Mode.TRAINING: LayerRepository(
|
||||||
|
repo_id="axolotl-ai-co/scattermoe",
|
||||||
|
layer_name="HFScatterMoEGatedMLP",
|
||||||
|
),
|
||||||
|
Mode.INFERENCE: LayerRepository(
|
||||||
|
repo_id="axolotl-ai-co/scattermoe",
|
||||||
|
layer_name="HFScatterMoEGatedMLP",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def _kernelize_model(self, model_type: str):
|
||||||
|
if model_type == "olmoe":
|
||||||
|
from transformers.models.olmoe.modeling_olmoe import OlmoeSparseMoeBlock
|
||||||
|
|
||||||
|
replace_kernel_forward_from_hub(
|
||||||
|
OlmoeSparseMoeBlock, "HFScatterMoEParallelExperts"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
model_moe_cls = get_model_moe_block(model_type)
|
||||||
|
replace_kernel_forward_from_hub(
|
||||||
|
model_moe_cls, "HFScatterMoEParallelExperts"
|
||||||
|
)
|
||||||
|
except Exception as err:
|
||||||
|
raise ValueError(f"Unsupported model type: {model_type}") from err
|
||||||
|
|
||||||
|
|
||||||
|
def get_model_moe_block(model_type: str):
|
||||||
|
module_path = f"transformers.models.{model_type}.modeling_{model_type}"
|
||||||
|
model_cls_prefix, _ = get_causal_lm_model_cls_prefix(model_type)
|
||||||
|
module = __import__(module_path, fromlist=[f"{model_cls_prefix}SparseMoeBlock"])
|
||||||
|
model_cls = getattr(module, f"{model_cls_prefix}SparseMoeBlock")
|
||||||
|
return model_cls
|
||||||
@@ -12,7 +12,6 @@ def save_compressed_model(
|
|||||||
model: PreTrainedModel,
|
model: PreTrainedModel,
|
||||||
output_dir: Union[str, bytes],
|
output_dir: Union[str, bytes],
|
||||||
trainer: Trainer,
|
trainer: Trainer,
|
||||||
safe_serialization: bool = False,
|
|
||||||
save_compressed: bool = False,
|
save_compressed: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -22,7 +21,6 @@ def save_compressed_model(
|
|||||||
model (PreTrainedModel): The model to be saved.
|
model (PreTrainedModel): The model to be saved.
|
||||||
output_dir (str or bytes): Path where the model files will be written.
|
output_dir (str or bytes): Path where the model files will be written.
|
||||||
trainer (Trainer): Hugging Face Trainer for process synchronization.
|
trainer (Trainer): Hugging Face Trainer for process synchronization.
|
||||||
safe_serialization (bool): Use safe serialization if True.
|
|
||||||
save_compressed (bool): Write compressed tensors if True.
|
save_compressed (bool): Write compressed tensors if True.
|
||||||
"""
|
"""
|
||||||
trainer.accelerator.wait_for_everyone()
|
trainer.accelerator.wait_for_everyone()
|
||||||
@@ -34,7 +32,6 @@ def save_compressed_model(
|
|||||||
modify_save_pretrained(model)
|
modify_save_pretrained(model)
|
||||||
model.save_pretrained(
|
model.save_pretrained(
|
||||||
output_dir,
|
output_dir,
|
||||||
safe_serialization=safe_serialization,
|
|
||||||
save_compressed=save_compressed,
|
save_compressed=save_compressed,
|
||||||
skip_sparsity_compression_stats=not save_compressed,
|
skip_sparsity_compression_stats=not save_compressed,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ from torch.distributed import DeviceMesh
|
|||||||
from transformers import (
|
from transformers import (
|
||||||
AutoModelForCausalLM,
|
AutoModelForCausalLM,
|
||||||
AutoModelForImageTextToText,
|
AutoModelForImageTextToText,
|
||||||
AutoModelForVision2Seq,
|
|
||||||
AwqConfig,
|
AwqConfig,
|
||||||
BitsAndBytesConfig,
|
BitsAndBytesConfig,
|
||||||
GPTQConfig,
|
GPTQConfig,
|
||||||
@@ -226,6 +225,7 @@ class ModelLoader:
|
|||||||
):
|
):
|
||||||
self.model = self.model.merge_and_unload()
|
self.model = self.model.merge_and_unload()
|
||||||
|
|
||||||
|
self._configure_experts_implementation()
|
||||||
self._apply_activation_checkpointing()
|
self._apply_activation_checkpointing()
|
||||||
self._resize_token_embeddings()
|
self._resize_token_embeddings()
|
||||||
self._adjust_model_config()
|
self._adjust_model_config()
|
||||||
@@ -233,6 +233,10 @@ class ModelLoader:
|
|||||||
self._configure_qat()
|
self._configure_qat()
|
||||||
log_gpu_memory_usage(LOG, "Memory usage after model load", 0)
|
log_gpu_memory_usage(LOG, "Memory usage after model load", 0)
|
||||||
|
|
||||||
|
def _configure_experts_implementation(self):
|
||||||
|
if self.cfg.experts_implementation is not None:
|
||||||
|
self.model.set_experts_implementation(self.cfg.experts_implementation)
|
||||||
|
|
||||||
def _apply_activation_checkpointing(self):
|
def _apply_activation_checkpointing(self):
|
||||||
if self.cfg.activation_offloading is True:
|
if self.cfg.activation_offloading is True:
|
||||||
from axolotl.core.trainers.mixins.activation_checkpointing import (
|
from axolotl.core.trainers.mixins.activation_checkpointing import (
|
||||||
@@ -434,7 +438,7 @@ class ModelLoader:
|
|||||||
"""
|
"""
|
||||||
if self.cfg.is_multimodal:
|
if self.cfg.is_multimodal:
|
||||||
self.auto_model_loader = MULTIMODAL_AUTO_MODEL_MAPPING.get(
|
self.auto_model_loader = MULTIMODAL_AUTO_MODEL_MAPPING.get(
|
||||||
self.model_config.model_type, AutoModelForVision2Seq
|
self.model_config.model_type, AutoModelForImageTextToText
|
||||||
)
|
)
|
||||||
if isinstance(self.auto_model_loader, str):
|
if isinstance(self.auto_model_loader, str):
|
||||||
self.auto_model_loader = AutoModelForImageTextToText
|
self.auto_model_loader = AutoModelForImageTextToText
|
||||||
@@ -476,6 +480,7 @@ class ModelLoader:
|
|||||||
max_memory = None
|
max_memory = None
|
||||||
|
|
||||||
self.model_kwargs["torch_dtype"] = self.cfg.torch_dtype
|
self.model_kwargs["torch_dtype"] = self.cfg.torch_dtype
|
||||||
|
self.model_kwargs["dtype"] = self.cfg.torch_dtype
|
||||||
|
|
||||||
is_ds_zero3 = is_deepspeed_zero3_enabled()
|
is_ds_zero3 = is_deepspeed_zero3_enabled()
|
||||||
|
|
||||||
@@ -670,7 +675,7 @@ class ModelLoader:
|
|||||||
Uses the selected loader when provided; otherwise falls back to the auto loader.
|
Uses the selected loader when provided; otherwise falls back to the auto loader.
|
||||||
"""
|
"""
|
||||||
loader = model_loader_class or self.auto_model_loader
|
loader = model_loader_class or self.auto_model_loader
|
||||||
if loader in [AutoModelForCausalLM, AutoModelForVision2Seq]:
|
if loader in [AutoModelForCausalLM, AutoModelForImageTextToText]:
|
||||||
model = loader.from_config(
|
model = loader.from_config(
|
||||||
config=self.model_config,
|
config=self.model_config,
|
||||||
trust_remote_code=self.cfg.trust_remote_code or False,
|
trust_remote_code=self.cfg.trust_remote_code or False,
|
||||||
@@ -788,6 +793,7 @@ class ModelLoader:
|
|||||||
# Use auto model loader (handles gptq and default cases)
|
# Use auto model loader (handles gptq and default cases)
|
||||||
model_loader_class = self.auto_model_loader
|
model_loader_class = self.auto_model_loader
|
||||||
|
|
||||||
|
self.model_kwargs["dtype"] = self.model_kwargs["torch_dtype"]
|
||||||
if self.cfg.reinit_weights:
|
if self.cfg.reinit_weights:
|
||||||
self.model = self._load_model_from_config(model_loader_class)
|
self.model = self._load_model_from_config(model_loader_class)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -220,13 +220,6 @@ class PatchManager:
|
|||||||
|
|
||||||
patch_qwen3_next_modeling_packing()
|
patch_qwen3_next_modeling_packing()
|
||||||
|
|
||||||
if self.cfg.model_config_type == "mistral3" and self.cfg.processor_type:
|
|
||||||
from axolotl.monkeypatch.models.mistral3.mistral_common_tokenizer import (
|
|
||||||
apply_mistral_tokenizer_image_patch,
|
|
||||||
)
|
|
||||||
|
|
||||||
apply_mistral_tokenizer_image_patch()
|
|
||||||
|
|
||||||
if self.cfg.model_config_type == "kimi_linear":
|
if self.cfg.model_config_type == "kimi_linear":
|
||||||
from axolotl.monkeypatch.models.kimi_linear.patch_kimi_linear import (
|
from axolotl.monkeypatch.models.kimi_linear.patch_kimi_linear import (
|
||||||
patch_kimi_model,
|
patch_kimi_model,
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ def load_processor(cfg: DictDefault, tokenizer: PreTrainedTokenizerBase):
|
|||||||
|
|
||||||
from axolotl.utils.mistral import HFMistralTokenizer
|
from axolotl.utils.mistral import HFMistralTokenizer
|
||||||
|
|
||||||
tokenization_mistral_common.MistralCommonTokenizer = HFMistralTokenizer
|
tokenization_mistral_common.MistralCommonBackend = HFMistralTokenizer
|
||||||
|
|
||||||
_patch_mistralcommontokenizer()
|
_patch_mistralcommontokenizer()
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,6 @@ class MambaLMHeadModel(nn.Module, GenerationMixin):
|
|||||||
self,
|
self,
|
||||||
save_directory: Union[str, os.PathLike],
|
save_directory: Union[str, os.PathLike],
|
||||||
state_dict: Optional[dict] = None,
|
state_dict: Optional[dict] = None,
|
||||||
safe_serialization: Optional[bool] = None,
|
|
||||||
):
|
):
|
||||||
if state_dict is None:
|
if state_dict is None:
|
||||||
state_dict = self.state_dict()
|
state_dict = self.state_dict()
|
||||||
|
|||||||
51
src/axolotl/monkeypatch/loss/eaft.py
Normal file
51
src/axolotl/monkeypatch/loss/eaft.py
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
"""
|
||||||
|
eaft (entropy-aware focal training) loss implementation
|
||||||
|
weights examples by entropy approximation from top-k logits
|
||||||
|
|
||||||
|
Reference: https://github.com/ymxyll/LlamaFactory-EAFT/blob/e2ce19e8efcc226450ee8f2b81dfe4e69f1f945d/src/llamafactory/train/trainer_utils.py
|
||||||
|
"""
|
||||||
|
|
||||||
|
import torch
|
||||||
|
import torch.nn.functional as F
|
||||||
|
|
||||||
|
|
||||||
|
def eaft_loss(outputs, labels, num_items_in_batch=None, alpha=1.0, k=20):
|
||||||
|
"""
|
||||||
|
compute eaft loss with entropy weighting
|
||||||
|
|
||||||
|
args:
|
||||||
|
outputs: model outputs containing logits
|
||||||
|
labels: target labels for computing loss
|
||||||
|
num_items_in_batch: for sample packing support
|
||||||
|
alpha: exponent for entropy weighting (default 1.0)
|
||||||
|
k: number of top logits for entropy approximation (default 20)
|
||||||
|
"""
|
||||||
|
logits = outputs.logits
|
||||||
|
|
||||||
|
shift_logits = logits[..., :-1, :].contiguous()
|
||||||
|
shift_labels = labels[..., 1:].contiguous()
|
||||||
|
|
||||||
|
vocab_size = shift_logits.size(-1)
|
||||||
|
shift_logits_view = shift_logits.view(-1, vocab_size)
|
||||||
|
shift_labels_view = shift_labels.view(-1)
|
||||||
|
|
||||||
|
mask = shift_labels_view != -100
|
||||||
|
|
||||||
|
with torch.no_grad():
|
||||||
|
top_k_logits, _ = torch.topk(
|
||||||
|
shift_logits_view[mask].float(), k=min(k, vocab_size), dim=-1
|
||||||
|
)
|
||||||
|
top_k_probs = F.softmax(top_k_logits, dim=-1)
|
||||||
|
entropy = -(top_k_probs * torch.log(top_k_probs + 1e-10)).sum(dim=-1)
|
||||||
|
weights = torch.pow(entropy, alpha)
|
||||||
|
|
||||||
|
loss_fct = torch.nn.CrossEntropyLoss(reduction="none")
|
||||||
|
per_token_loss = loss_fct(shift_logits_view[mask], shift_labels_view[mask])
|
||||||
|
weighted_loss = per_token_loss * weights
|
||||||
|
|
||||||
|
if num_items_in_batch is not None:
|
||||||
|
loss = weighted_loss.sum() / num_items_in_batch
|
||||||
|
else:
|
||||||
|
loss = weighted_loss.mean()
|
||||||
|
|
||||||
|
return loss
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Monkeypatch to fix inefficient tensor conversion in MistralCommonTokenizer.apply_chat_template
|
Monkeypatch to fix inefficient tensor conversion in MistralCommonBackend.apply_chat_template
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
@@ -12,11 +12,11 @@ LOG = get_logger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def apply_mistral_tokenizer_image_patch():
|
def apply_mistral_tokenizer_image_patch():
|
||||||
"""Apply patch to MistralCommonTokenizer.apply_chat_template to fix image tensor conversion."""
|
"""Apply patch to MistralCommonBackend.apply_chat_template to fix image tensor conversion."""
|
||||||
from transformers.tokenization_mistral_common import MistralCommonTokenizer
|
from transformers.tokenization_mistral_common import MistralCommonBackend
|
||||||
|
|
||||||
# Get original source
|
# Get original source
|
||||||
original_source = inspect.getsource(MistralCommonTokenizer.apply_chat_template)
|
original_source = inspect.getsource(MistralCommonBackend.apply_chat_template)
|
||||||
original_source, _ = detab_code(original_source)
|
original_source, _ = detab_code(original_source)
|
||||||
|
|
||||||
# Define the replacement
|
# Define the replacement
|
||||||
@@ -41,7 +41,7 @@ def apply_mistral_tokenizer_image_patch():
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Load necessary imports from the module
|
# Load necessary imports from the module
|
||||||
module_name = MistralCommonTokenizer.__module__
|
module_name = MistralCommonBackend.__module__
|
||||||
module = importlib.import_module(module_name)
|
module = importlib.import_module(module_name)
|
||||||
|
|
||||||
# Detect what needs to be imported
|
# Detect what needs to be imported
|
||||||
@@ -79,7 +79,7 @@ def apply_mistral_tokenizer_image_patch():
|
|||||||
exec(patched_source, globals()) # nosec B102
|
exec(patched_source, globals()) # nosec B102
|
||||||
|
|
||||||
# Replace the method
|
# Replace the method
|
||||||
MistralCommonTokenizer.apply_chat_template = patched_apply_chat_template
|
MistralCommonBackend.apply_chat_template = patched_apply_chat_template
|
||||||
LOG.info("Successfully applied MistralCommonTokenizer tensor conversion patch")
|
LOG.info("Successfully applied MistralCommonBackend tensor conversion patch")
|
||||||
else:
|
else:
|
||||||
LOG.warning("Could not find target code for MistralCommonTokenizer patching")
|
LOG.warning("Could not find target code for MistralCommonBackend patching")
|
||||||
|
|||||||
@@ -155,7 +155,6 @@ class ReLoRACallback(TrainerCallback):
|
|||||||
f"{PREFIX_CHECKPOINT_DIR}-{state.global_step}",
|
f"{PREFIX_CHECKPOINT_DIR}-{state.global_step}",
|
||||||
"adapter",
|
"adapter",
|
||||||
),
|
),
|
||||||
safe_serialization=True,
|
|
||||||
)
|
)
|
||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
merge_and_save(
|
merge_and_save(
|
||||||
@@ -214,7 +213,7 @@ class ReLoRACallback(TrainerCallback):
|
|||||||
|
|
||||||
self.last_full_model = checkpoint_folder
|
self.last_full_model = checkpoint_folder
|
||||||
else:
|
else:
|
||||||
model.model.save_pretrained(checkpoint_folder, safe_serialization=True)
|
model.model.save_pretrained(checkpoint_folder)
|
||||||
|
|
||||||
return control
|
return control
|
||||||
|
|
||||||
|
|||||||
@@ -52,9 +52,15 @@ def patch_prepare_context_parallel_inputs() -> None:
|
|||||||
if item in patched_source:
|
if item in patched_source:
|
||||||
items_to_import.append(item)
|
items_to_import.append(item)
|
||||||
|
|
||||||
exec(f"from {module_name} import ({', '.join(items_to_import)})", globals())
|
# Use a separate namespace to capture the exec'd function
|
||||||
exec(patched_source, globals())
|
namespace = {}
|
||||||
|
exec(f"from {module_name} import ({', '.join(items_to_import)})", namespace)
|
||||||
|
exec(patched_source, namespace)
|
||||||
|
|
||||||
|
# Explicitly get the function from the namespace
|
||||||
|
axolotl_prepare_context_parallel_inputs = namespace[
|
||||||
|
"axolotl_prepare_context_parallel_inputs"
|
||||||
|
]
|
||||||
Trainer._original_prepare_context_parallel_inputs = (
|
Trainer._original_prepare_context_parallel_inputs = (
|
||||||
Trainer._prepare_context_parallel_inputs
|
Trainer._prepare_context_parallel_inputs
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ from transformers.models.voxtral import VoxtralProcessor
|
|||||||
|
|
||||||
from axolotl.utils.dict import remove_none_values
|
from axolotl.utils.dict import remove_none_values
|
||||||
from axolotl.utils.logging import get_logger
|
from axolotl.utils.logging import get_logger
|
||||||
from axolotl.utils.mistral.mistral3_processor import Mistral3Processor
|
|
||||||
|
|
||||||
LOG = get_logger(__name__)
|
LOG = get_logger(__name__)
|
||||||
|
|
||||||
@@ -430,7 +429,7 @@ class Mistral3ProcessingStrategy(ProcessingStrategy):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
processor: Mistral3Processor,
|
processor,
|
||||||
chat_template: Optional[str] = None,
|
chat_template: Optional[str] = None,
|
||||||
image_size: int | tuple[int, int] | None = None,
|
image_size: int | tuple[int, int] | None = None,
|
||||||
image_resize_algorithm: Resampling | None = None,
|
image_resize_algorithm: Resampling | None = None,
|
||||||
@@ -493,6 +492,8 @@ def get_processing_strategy(
|
|||||||
image_size: int | tuple[int, int] | None = None,
|
image_size: int | tuple[int, int] | None = None,
|
||||||
image_resize_algorithm: Resampling | None = None,
|
image_resize_algorithm: Resampling | None = None,
|
||||||
):
|
):
|
||||||
|
from axolotl.utils.mistral.mistral3_processor import Mistral3Processor
|
||||||
|
|
||||||
processing_kwargs = {
|
processing_kwargs = {
|
||||||
"processor": processor,
|
"processor": processor,
|
||||||
"chat_template": chat_template,
|
"chat_template": chat_template,
|
||||||
|
|||||||
@@ -150,6 +150,8 @@ class ChatTemplatePrompter(Prompter):
|
|||||||
|
|
||||||
return self.tokenizer.apply_chat_template(
|
return self.tokenizer.apply_chat_template(
|
||||||
conversation,
|
conversation,
|
||||||
|
tokenize=True,
|
||||||
|
return_dict=False,
|
||||||
**chat_template_kwargs,
|
**chat_template_kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -135,16 +135,13 @@ def setup_reference_model(
|
|||||||
return model_ref
|
return model_ref
|
||||||
|
|
||||||
|
|
||||||
def setup_signal_handler(
|
def setup_signal_handler(cfg: DictDefault, model: PreTrainedModel):
|
||||||
cfg: DictDefault, model: PreTrainedModel, safe_serialization: bool
|
|
||||||
):
|
|
||||||
"""
|
"""
|
||||||
Set up signal handler for graceful termination.
|
Set up signal handler for graceful termination.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
cfg: Dictionary mapping `axolotl` config keys to values.
|
cfg: Dictionary mapping `axolotl` config keys to values.
|
||||||
model: The model to save on termination
|
model: The model to save on termination
|
||||||
safe_serialization: Whether to use safe serialization when saving
|
|
||||||
"""
|
"""
|
||||||
# ray workers don't have access to this signal
|
# ray workers don't have access to this signal
|
||||||
if cfg.local_rank == 0 and not cfg.use_ray:
|
if cfg.local_rank == 0 and not cfg.use_ray:
|
||||||
@@ -152,9 +149,7 @@ def setup_signal_handler(
|
|||||||
def terminate_handler(_, __, model_weakref):
|
def terminate_handler(_, __, model_weakref):
|
||||||
if model_weakref() is not None:
|
if model_weakref() is not None:
|
||||||
_model = model_weakref()
|
_model = model_weakref()
|
||||||
_model.save_pretrained(
|
_model.save_pretrained(cfg.output_dir)
|
||||||
cfg.output_dir, safe_serialization=safe_serialization
|
|
||||||
)
|
|
||||||
|
|
||||||
cleanup_distributed()
|
cleanup_distributed()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
@@ -219,7 +214,6 @@ def save_trained_model(
|
|||||||
cfg: DictDefault,
|
cfg: DictDefault,
|
||||||
trainer: Any,
|
trainer: Any,
|
||||||
model: PreTrainedModel,
|
model: PreTrainedModel,
|
||||||
safe_serialization: bool,
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Save the trained model according to configuration and training setup.
|
Save the trained model according to configuration and training setup.
|
||||||
@@ -228,7 +222,6 @@ def save_trained_model(
|
|||||||
cfg: Dictionary mapping `axolotl` config keys to values.
|
cfg: Dictionary mapping `axolotl` config keys to values.
|
||||||
trainer: The trainer object.
|
trainer: The trainer object.
|
||||||
model: The trained model to save.
|
model: The trained model to save.
|
||||||
safe_serialization: Whether to use safe serialization.
|
|
||||||
"""
|
"""
|
||||||
LOG.info(f"Training completed! Saving trained model to {cfg.output_dir}.")
|
LOG.info(f"Training completed! Saving trained model to {cfg.output_dir}.")
|
||||||
|
|
||||||
@@ -283,7 +276,6 @@ def save_trained_model(
|
|||||||
merge_fsdp_weights(
|
merge_fsdp_weights(
|
||||||
checkpoint_dir=str(fsdp_dir),
|
checkpoint_dir=str(fsdp_dir),
|
||||||
output_path=merged_path,
|
output_path=merged_path,
|
||||||
safe_serialization=True,
|
|
||||||
)
|
)
|
||||||
trainer.accelerator.wait_for_everyone()
|
trainer.accelerator.wait_for_everyone()
|
||||||
if trainer.accelerator.is_main_process:
|
if trainer.accelerator.is_main_process:
|
||||||
@@ -330,11 +322,9 @@ def save_trained_model(
|
|||||||
pass
|
pass
|
||||||
elif cfg.local_rank == 0:
|
elif cfg.local_rank == 0:
|
||||||
if cfg.rl and cfg.adapter and not cfg.rl_adapter_ref_model:
|
if cfg.rl and cfg.adapter and not cfg.rl_adapter_ref_model:
|
||||||
trainer.model.save_pretrained(
|
trainer.model.save_pretrained(cfg.output_dir)
|
||||||
cfg.output_dir, safe_serialization=safe_serialization
|
|
||||||
)
|
|
||||||
|
|
||||||
model.save_pretrained(cfg.output_dir, safe_serialization=safe_serialization)
|
model.save_pretrained(cfg.output_dir)
|
||||||
|
|
||||||
if hasattr(cfg, "llmcompressor") and cfg.llmcompressor:
|
if hasattr(cfg, "llmcompressor") and cfg.llmcompressor:
|
||||||
# TODO: add integration support so this can be implemented completely within the plugin
|
# TODO: add integration support so this can be implemented completely within the plugin
|
||||||
@@ -344,7 +334,6 @@ def save_trained_model(
|
|||||||
model=model,
|
model=model,
|
||||||
output_dir=cfg.output_dir,
|
output_dir=cfg.output_dir,
|
||||||
trainer=trainer,
|
trainer=trainer,
|
||||||
safe_serialization=safe_serialization,
|
|
||||||
save_compressed=cfg.llmcompressor.save_compressed,
|
save_compressed=cfg.llmcompressor.save_compressed,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -449,7 +438,6 @@ def handle_untrained_tokens_fix(
|
|||||||
model: PreTrainedModel,
|
model: PreTrainedModel,
|
||||||
tokenizer: PreTrainedTokenizer,
|
tokenizer: PreTrainedTokenizer,
|
||||||
train_dataset: Dataset,
|
train_dataset: Dataset,
|
||||||
safe_serialization: bool,
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Apply fixes for untrained tokens if configured.
|
Apply fixes for untrained tokens if configured.
|
||||||
@@ -459,7 +447,6 @@ def handle_untrained_tokens_fix(
|
|||||||
model: The model to apply fixes to.
|
model: The model to apply fixes to.
|
||||||
tokenizer: The tokenizer for token identification.
|
tokenizer: The tokenizer for token identification.
|
||||||
train_dataset: The training dataset to use.
|
train_dataset: The training dataset to use.
|
||||||
safe_serialization: Whether to use safe serialization when saving.
|
|
||||||
"""
|
"""
|
||||||
if not cfg.fix_untrained_tokens:
|
if not cfg.fix_untrained_tokens:
|
||||||
return
|
return
|
||||||
@@ -483,9 +470,7 @@ def handle_untrained_tokens_fix(
|
|||||||
fix_untrained_tokens(model, tokenizer, train_dataset, **fix_kwargs)
|
fix_untrained_tokens(model, tokenizer, train_dataset, **fix_kwargs)
|
||||||
|
|
||||||
if cfg.local_rank == 0:
|
if cfg.local_rank == 0:
|
||||||
model.save_pretrained(
|
model.save_pretrained(str(Path(cfg.output_dir)))
|
||||||
str(Path(cfg.output_dir)), safe_serialization=safe_serialization
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_model_and_trainer(
|
def setup_model_and_trainer(
|
||||||
@@ -582,15 +567,12 @@ def train(
|
|||||||
) = setup_model_and_trainer(cfg, dataset_meta)
|
) = setup_model_and_trainer(cfg, dataset_meta)
|
||||||
|
|
||||||
# Handle untrained tokens if configured
|
# Handle untrained tokens if configured
|
||||||
safe_serialization = cfg.save_safetensors is True
|
|
||||||
train_dataset = dataset_meta.train_dataset
|
train_dataset = dataset_meta.train_dataset
|
||||||
handle_untrained_tokens_fix(
|
handle_untrained_tokens_fix(cfg, model, tokenizer, train_dataset)
|
||||||
cfg, model, tokenizer, train_dataset, safe_serialization
|
|
||||||
)
|
|
||||||
|
|
||||||
# Additional setup
|
# Additional setup
|
||||||
save_initial_configs(cfg, tokenizer, model, peft_config, processor)
|
save_initial_configs(cfg, tokenizer, model, peft_config, processor)
|
||||||
setup_signal_handler(cfg, model, safe_serialization)
|
setup_signal_handler(cfg, model)
|
||||||
setup_model_card(cfg)
|
setup_model_card(cfg)
|
||||||
|
|
||||||
# Execute the training
|
# Execute the training
|
||||||
@@ -602,7 +584,7 @@ def train(
|
|||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
|
|
||||||
# Save the trained model and cleanup
|
# Save the trained model and cleanup
|
||||||
save_trained_model(cfg, trainer, model, safe_serialization)
|
save_trained_model(cfg, trainer, model)
|
||||||
tokenizer.save_pretrained(
|
tokenizer.save_pretrained(
|
||||||
str(Path(cfg.output_dir)), save_jinja_files=cfg.tokenizer_save_jinja_files
|
str(Path(cfg.output_dir)), save_jinja_files=cfg.tokenizer_save_jinja_files
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ from torch import Tensor
|
|||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
from transformers.modeling_outputs import CausalLMOutput
|
from transformers.modeling_outputs import CausalLMOutput
|
||||||
from transformers.modeling_utils import PreTrainedModel
|
from transformers.modeling_utils import PreTrainedModel
|
||||||
from transformers.tokenization_utils import PreTrainedTokenizer
|
|
||||||
|
try:
|
||||||
|
from transformers.tokenization_python import PreTrainedTokenizer
|
||||||
|
except ImportError:
|
||||||
|
from transformers.tokenization_utils import PreTrainedTokenizer
|
||||||
|
|
||||||
from axolotl.utils.distributed import is_main_process
|
from axolotl.utils.distributed import is_main_process
|
||||||
|
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ def _drop_long_sequences(
|
|||||||
|
|
||||||
return (len_prompt + len_completion) <= sequence_len
|
return (len_prompt + len_completion) <= sequence_len
|
||||||
|
|
||||||
if rl is RLType.GRPO:
|
if rl in {RLType.GRPO, RLType.GDPO}:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
raise ValueError("Unknown RL type")
|
raise ValueError("Unknown RL type")
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import numpy as np
|
|||||||
from mistral_common.protocol.instruct.validator import ValidationMode
|
from mistral_common.protocol.instruct.validator import ValidationMode
|
||||||
from mistral_common.tokens.tokenizers.utils import download_tokenizer_from_hf_hub
|
from mistral_common.tokens.tokenizers.utils import download_tokenizer_from_hf_hub
|
||||||
from torch import Tensor
|
from torch import Tensor
|
||||||
from transformers.tokenization_mistral_common import MistralCommonTokenizer
|
from transformers.tokenization_mistral_common import MistralCommonBackend
|
||||||
from transformers.tokenization_utils_base import VERY_LARGE_INTEGER
|
from transformers.tokenization_utils_base import VERY_LARGE_INTEGER
|
||||||
|
|
||||||
|
|
||||||
class HFMistralTokenizer(MistralCommonTokenizer):
|
class HFMistralTokenizer(MistralCommonBackend):
|
||||||
"""
|
"""
|
||||||
Wraps mistral_common.tokens.tokenizers.mistral.MistralTokenizer
|
Wraps mistral_common.tokens.tokenizers.mistral.MistralTokenizer
|
||||||
and exposes HuggingFace API for special tokens.
|
and exposes HuggingFace API for special tokens.
|
||||||
@@ -37,11 +37,19 @@ class HFMistralTokenizer(MistralCommonTokenizer):
|
|||||||
def name_or_path(self) -> str:
|
def name_or_path(self) -> str:
|
||||||
return self._name_or_path
|
return self._name_or_path
|
||||||
|
|
||||||
|
@name_or_path.setter
|
||||||
|
def name_or_path(self, name_or_path: str) -> None:
|
||||||
|
self._name_or_path = name_or_path
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def chat_template(self) -> str | None:
|
def chat_template(self) -> str | None:
|
||||||
"""Chat template is not supported. Dummy method to satisfy HuggingFace API."""
|
"""Chat template is not supported. Dummy method to satisfy HuggingFace API."""
|
||||||
return "[This is a dummy chat template]"
|
return "[This is a dummy chat template]"
|
||||||
|
|
||||||
|
@chat_template.setter
|
||||||
|
def chat_template(self, chat_template: str | None) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
def _set_mode(self, mode: ValidationMode):
|
def _set_mode(self, mode: ValidationMode):
|
||||||
"""Set the mode of the MistralRequestValidator.
|
"""Set the mode of the MistralRequestValidator.
|
||||||
|
|
||||||
@@ -133,7 +141,7 @@ class HFMistralTokenizer(MistralCommonTokenizer):
|
|||||||
r"""
|
r"""
|
||||||
Patched fn to pass `name_or_path` and remove extra kwargs.
|
Patched fn to pass `name_or_path` and remove extra kwargs.
|
||||||
|
|
||||||
Instantiate a `MistralCommonTokenizer` from a predefined
|
Instantiate a `MistralCommonBackend` from a predefined
|
||||||
tokenizer.
|
tokenizer.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -142,7 +150,7 @@ class HFMistralTokenizer(MistralCommonTokenizer):
|
|||||||
|
|
||||||
- A string, the *model id* of a predefined tokenizer hosted inside a model repo on huggingface.co.
|
- A string, the *model id* of a predefined tokenizer hosted inside a model repo on huggingface.co.
|
||||||
- A path to a *directory* containing the tokenizer config, for instance saved
|
- A path to a *directory* containing the tokenizer config, for instance saved
|
||||||
using the [`MistralCommonTokenizer.tokenization_mistral_common.save_pretrained`] method, e.g.,
|
using the [`MistralCommonBackend.tokenization_mistral_common.save_pretrained`] method, e.g.,
|
||||||
`./my_model_directory/`.
|
`./my_model_directory/`.
|
||||||
mode (`ValidationMode`, *optional*, defaults to `ValidationMode.test`):
|
mode (`ValidationMode`, *optional*, defaults to `ValidationMode.test`):
|
||||||
Validation mode for the `MistralTokenizer` tokenizer.
|
Validation mode for the `MistralTokenizer` tokenizer.
|
||||||
@@ -154,7 +162,7 @@ class HFMistralTokenizer(MistralCommonTokenizer):
|
|||||||
exist.
|
exist.
|
||||||
token (`str` or *bool*, *optional*):
|
token (`str` or *bool*, *optional*):
|
||||||
The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
|
The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
|
||||||
when running `huggingface-cli login` (stored in `~/.huggingface`).
|
when running `hf auth login` (stored in `~/.huggingface`).
|
||||||
local_files_only (`bool`, *optional*, defaults to `False`):
|
local_files_only (`bool`, *optional*, defaults to `False`):
|
||||||
Whether or not to only rely on local files and not to attempt to download any files.
|
Whether or not to only rely on local files and not to attempt to download any files.
|
||||||
revision (`str`, *optional*, defaults to `"main"`):
|
revision (`str`, *optional*, defaults to `"main"`):
|
||||||
@@ -179,12 +187,12 @@ class HFMistralTokenizer(MistralCommonTokenizer):
|
|||||||
Whether or not the model should cleanup the spaces that were added when splitting the input text during the
|
Whether or not the model should cleanup the spaces that were added when splitting the input text during the
|
||||||
tokenization process.
|
tokenization process.
|
||||||
kwargs (additional keyword arguments, *optional*):
|
kwargs (additional keyword arguments, *optional*):
|
||||||
Not supported by `MistralCommonTokenizer.from_pretrained`.
|
Not supported by `MistralCommonBackend.from_pretrained`.
|
||||||
Will raise an error if used.
|
Will raise an error if used.
|
||||||
"""
|
"""
|
||||||
if init_inputs:
|
if init_inputs:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"`init_inputs` are not supported by `MistralCommonTokenizer.from_pretrained`."
|
"`init_inputs` are not supported by `MistralCommonBackend.from_pretrained`."
|
||||||
)
|
)
|
||||||
|
|
||||||
# Delete trust_remote_code as it does nothing
|
# Delete trust_remote_code as it does nothing
|
||||||
@@ -196,7 +204,7 @@ class HFMistralTokenizer(MistralCommonTokenizer):
|
|||||||
# Handle kwargs and AutoTokenizer case
|
# Handle kwargs and AutoTokenizer case
|
||||||
if kwargs and not kwargs.keys() == {"_from_auto"}:
|
if kwargs and not kwargs.keys() == {"_from_auto"}:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Kwargs {list(kwargs.keys())} are not supported by `MistralCommonTokenizer.from_pretrained`."
|
f"Kwargs {list(kwargs.keys())} are not supported by `MistralCommonBackend.from_pretrained`."
|
||||||
)
|
)
|
||||||
|
|
||||||
if not os.path.isfile(pretrained_model_name_or_path):
|
if not os.path.isfile(pretrained_model_name_or_path):
|
||||||
|
|||||||
@@ -619,6 +619,13 @@ class AxolotlInputConfig(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
experts_implementation: str | None = Field(
|
||||||
|
default=None,
|
||||||
|
json_schema_extra={
|
||||||
|
"description": "Which experts implementation to use for MoE models,"
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
scaling_softmax: bool | None = Field(
|
scaling_softmax: bool | None = Field(
|
||||||
default=None,
|
default=None,
|
||||||
json_schema_extra={
|
json_schema_extra={
|
||||||
@@ -676,6 +683,24 @@ class AxolotlInputConfig(
|
|||||||
"description": "Number of chunks to use for chunked cross entropy loss"
|
"description": "Number of chunks to use for chunked cross entropy loss"
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
use_eaft: bool | None = Field(
|
||||||
|
default=None,
|
||||||
|
json_schema_extra={
|
||||||
|
"description": "Enable Entropy-Aware Focal Training loss (EAFT)"
|
||||||
|
},
|
||||||
|
)
|
||||||
|
eaft_alpha: float | None = Field(
|
||||||
|
default=1.0,
|
||||||
|
json_schema_extra={
|
||||||
|
"description": "Exponent for entropy weighting in EAFT (default: 1.0)"
|
||||||
|
},
|
||||||
|
)
|
||||||
|
eaft_k: int | None = Field(
|
||||||
|
default=20,
|
||||||
|
json_schema_extra={
|
||||||
|
"description": "Number of top logits for entropy approximation (default: 20)"
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
tiled_mlp: bool | None = Field(
|
tiled_mlp: bool | None = Field(
|
||||||
default=None,
|
default=None,
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class RLType(str, Enum):
|
|||||||
"""RL trainer type configuration subset"""
|
"""RL trainer type configuration subset"""
|
||||||
|
|
||||||
DPO = "dpo"
|
DPO = "dpo"
|
||||||
|
GDPO = "gdpo"
|
||||||
GRPO = "grpo"
|
GRPO = "grpo"
|
||||||
IPO = "ipo"
|
IPO = "ipo"
|
||||||
ORPO = "orpo"
|
ORPO = "orpo"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ FSDP Configuration Schema
|
|||||||
|
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import AliasChoices, BaseModel, Field
|
||||||
|
|
||||||
|
|
||||||
class FSDPConfig(BaseModel):
|
class FSDPConfig(BaseModel):
|
||||||
@@ -12,6 +12,11 @@ class FSDPConfig(BaseModel):
|
|||||||
FSDP Configuration Schema
|
FSDP Configuration Schema
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
fsdp_version: int | None = Field(
|
||||||
|
validation_alias=AliasChoices("fsdp_version", "version"),
|
||||||
|
default=None,
|
||||||
|
json_schema_extra={"description": "FSDP version"},
|
||||||
|
)
|
||||||
activation_checkpointing: bool | None = Field(
|
activation_checkpointing: bool | None = Field(
|
||||||
default=None,
|
default=None,
|
||||||
description="Enable activation checkpointing to reduce memory usage during forward passes",
|
description="Enable activation checkpointing to reduce memory usage during forward passes",
|
||||||
|
|||||||
@@ -123,10 +123,22 @@ class ModelOutputConfig(BaseModel):
|
|||||||
save_safetensors: bool | None = Field(
|
save_safetensors: bool | None = Field(
|
||||||
default=True,
|
default=True,
|
||||||
json_schema_extra={
|
json_schema_extra={
|
||||||
"description": "Save model as safetensors (require safetensors package). Default True"
|
"description": "Whether to save the model using safetensors format. Defaults to True."
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@field_validator("save_safetensors")
|
||||||
|
@classmethod
|
||||||
|
def validate_save_safetensors(cls, v):
|
||||||
|
if v is False:
|
||||||
|
raise ValueError(
|
||||||
|
"save_safetensors=False is not supported in Transformers V5. "
|
||||||
|
"Transformers V5 always uses safetensors format for model serialization. "
|
||||||
|
"This field is deprecated and will be removed in a future version."
|
||||||
|
)
|
||||||
|
# Allow None and True, will default to True if None
|
||||||
|
return True if v is None else v
|
||||||
|
|
||||||
|
|
||||||
class SpecialTokensConfig(BaseModel):
|
class SpecialTokensConfig(BaseModel):
|
||||||
"""Special tokens configuration subset"""
|
"""Special tokens configuration subset"""
|
||||||
|
|||||||
@@ -179,3 +179,13 @@ class TRLConfig(BaseModel):
|
|||||||
"description": "Path to custom rollout function. Must be importable from current dir."
|
"description": "Path to custom rollout function. Must be importable from current dir."
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
multi_objective_aggregation: (
|
||||||
|
Literal["sum_then_normalize", "normalize_then_sum"] | None
|
||||||
|
) = Field(
|
||||||
|
default=None,
|
||||||
|
json_schema_extra={
|
||||||
|
"description": "Multi-objective reward aggregation strategy. "
|
||||||
|
"'sum_then_normalize' (GRPO default): weights and sums rewards first, then normalizes. "
|
||||||
|
"'normalize_then_sum' (GDPO): normalizes each reward independently, then sums."
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|||||||
@@ -746,6 +746,19 @@ class RLValidationMixin:
|
|||||||
)
|
)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@model_validator(mode="before")
|
||||||
|
@classmethod
|
||||||
|
def check_gdpo(cls, data):
|
||||||
|
if (
|
||||||
|
data.get("rl") == "gdpo"
|
||||||
|
and data.get("trl", {}).get("multi_objective_aggregation")
|
||||||
|
== "sum_then_normalize"
|
||||||
|
):
|
||||||
|
raise ValueError(
|
||||||
|
"`multi_objective_aggregation` value set as `sum_then_normalize` => GRPO, but GDPO was selected"
|
||||||
|
)
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
class OptimizationValidationMixin:
|
class OptimizationValidationMixin:
|
||||||
"""Validation methods related to optimization and performance."""
|
"""Validation methods related to optimization and performance."""
|
||||||
@@ -887,6 +900,43 @@ class OptimizationValidationMixin:
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@model_validator(mode="before")
|
||||||
|
@classmethod
|
||||||
|
def check_fsdp_config_kwargs_prefix(cls, data):
|
||||||
|
if fsdp_config := data.get("fsdp_config"):
|
||||||
|
should_fix = False
|
||||||
|
for key, _ in fsdp_config.items():
|
||||||
|
if key.startswith("fsdp_"):
|
||||||
|
should_fix = True
|
||||||
|
LOG.warning_once(
|
||||||
|
"Configuring FSDP fields with the `fsdp_` prefix is deprecated. "
|
||||||
|
"Please omit the `fsdp_` prefix from the any fields in `fsdp_config`."
|
||||||
|
)
|
||||||
|
if should_fix:
|
||||||
|
update_fsdp_config = {}
|
||||||
|
for key, value in fsdp_config.items():
|
||||||
|
if key.startswith("fsdp_") and key != "fsdp_version":
|
||||||
|
update_fsdp_config[key.replace("fsdp_", "")] = value
|
||||||
|
else:
|
||||||
|
update_fsdp_config[key] = value
|
||||||
|
data["fsdp_config"] = update_fsdp_config
|
||||||
|
return data
|
||||||
|
|
||||||
|
@model_validator(mode="before")
|
||||||
|
@classmethod
|
||||||
|
def check_fsdp_version_in_fsdp_config(cls, data):
|
||||||
|
fsdp_config = data.get("fsdp_config") or {}
|
||||||
|
fsdp_version = data.get("fsdp_version", None)
|
||||||
|
if not fsdp_version and fsdp_config and fsdp_config.get("version"):
|
||||||
|
fsdp_cfg_version = fsdp_config.pop("version")
|
||||||
|
data["fsdp_version"] = fsdp_cfg_version
|
||||||
|
data["fsdp_config"]["fsdp_version"] = fsdp_cfg_version
|
||||||
|
elif not fsdp_version and fsdp_config and fsdp_config.get("fsdp_version"):
|
||||||
|
data["fsdp_version"] = fsdp_config.get("fsdp_version")
|
||||||
|
if fsdp_version and fsdp_config and not fsdp_config.get("fsdp_version"):
|
||||||
|
data["fsdp_config"]["fsdp_version"] = fsdp_version
|
||||||
|
return data
|
||||||
|
|
||||||
@model_validator(mode="after")
|
@model_validator(mode="after")
|
||||||
def check_fsdp_offload_w_8bit_optimizer(self):
|
def check_fsdp_offload_w_8bit_optimizer(self):
|
||||||
if (
|
if (
|
||||||
@@ -988,40 +1038,6 @@ class OptimizationValidationMixin:
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@model_validator(mode="before")
|
|
||||||
@classmethod
|
|
||||||
def check_fsdp_version_in_fsdp_config(cls, data):
|
|
||||||
fsdp_config = data.get("fsdp_config") or {}
|
|
||||||
if fsdp_config and fsdp_config.get("fsdp_version"):
|
|
||||||
LOG.warning(
|
|
||||||
"Configuring `fsdp_version` in `fsdp_config` is deprecated. "
|
|
||||||
"Please configure `fsdp_version` as a top-level field."
|
|
||||||
)
|
|
||||||
data["fsdp_version"] = fsdp_config.pop("fsdp_version")
|
|
||||||
return data
|
|
||||||
|
|
||||||
@model_validator(mode="before")
|
|
||||||
@classmethod
|
|
||||||
def check_fsdp_config_kwargs_prefix(cls, data):
|
|
||||||
if fsdp_config := data.get("fsdp_config"):
|
|
||||||
should_fix = False
|
|
||||||
for key, _ in fsdp_config.items():
|
|
||||||
if key.startswith("fsdp_"):
|
|
||||||
should_fix = True
|
|
||||||
LOG.warning_once(
|
|
||||||
"Configuring FSDP fields with the `fsdp_` prefix is deprecated. "
|
|
||||||
"Please omit the `fsdp_` prefix from the any fields in `fsdp_config`."
|
|
||||||
)
|
|
||||||
if should_fix:
|
|
||||||
update_fsdp_config = {}
|
|
||||||
for key, value in fsdp_config.items():
|
|
||||||
if key.startswith("fsdp_") and key != "fsdp_version":
|
|
||||||
update_fsdp_config[key.replace("fsdp_", "")] = value
|
|
||||||
else:
|
|
||||||
update_fsdp_config[key] = value
|
|
||||||
data["fsdp_config"] = update_fsdp_config
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
class SystemValidationMixin:
|
class SystemValidationMixin:
|
||||||
"""Validation methods related to system and hardware configuration."""
|
"""Validation methods related to system and hardware configuration."""
|
||||||
|
|||||||
@@ -83,6 +83,12 @@ def download_smollm2_135m_model():
|
|||||||
snapshot_download_w_retry("HuggingFaceTB/SmolLM2-135M", repo_type="model")
|
snapshot_download_w_retry("HuggingFaceTB/SmolLM2-135M", repo_type="model")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
|
def download_smollm2_135m_instruct_model():
|
||||||
|
# download the model
|
||||||
|
snapshot_download_w_retry("HuggingFaceTB/SmolLM2-135M-Instruct", repo_type="model")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session", autouse=True)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
def download_smollm2_135m_gptq_model():
|
def download_smollm2_135m_gptq_model():
|
||||||
# download the model
|
# download the model
|
||||||
@@ -143,12 +149,20 @@ def download_argilla_distilabel_intel_orca_dpo_dataset():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# @pytest.fixture(scope="session", autouse=True)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
# def download_argilla_ultrafeedback_binarized_preferences_cleaned_dataset():
|
def download_argilla_ultrafeedback_binarized_preferences_cleaned_dataset():
|
||||||
# # download the dataset
|
# download the dataset
|
||||||
# snapshot_download_w_retry(
|
snapshot_download_w_retry(
|
||||||
# "argilla/ultrafeedback-binarized-preferences-cleaned", repo_type="dataset"
|
"argilla/ultrafeedback-binarized-preferences-cleaned", repo_type="dataset"
|
||||||
# )
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
|
def download_argilla_ultrafeedback_binarized_preferences_cleaned_kto_dataset():
|
||||||
|
# download the dataset
|
||||||
|
snapshot_download_w_retry(
|
||||||
|
"argilla/ultrafeedback-binarized-preferences-cleaned-kto", repo_type="dataset"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# @pytest.fixture(scope="session", autouse=True)
|
# @pytest.fixture(scope="session", autouse=True)
|
||||||
@@ -251,7 +265,9 @@ def download_llama_1b_model_fixture():
|
|||||||
def download_llama3_8b_model_fixture():
|
def download_llama3_8b_model_fixture():
|
||||||
# download the tokenizer only
|
# download the tokenizer only
|
||||||
snapshot_download_w_retry(
|
snapshot_download_w_retry(
|
||||||
"NousResearch/Meta-Llama-3-8B", repo_type="model", allow_patterns=["*token*"]
|
"NousResearch/Meta-Llama-3-8B",
|
||||||
|
repo_type="model",
|
||||||
|
allow_patterns=["*token*", "config.json"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -261,7 +277,7 @@ def download_llama3_8b_instruct_model_fixture():
|
|||||||
snapshot_download_w_retry(
|
snapshot_download_w_retry(
|
||||||
"NousResearch/Meta-Llama-3-8B-Instruct",
|
"NousResearch/Meta-Llama-3-8B-Instruct",
|
||||||
repo_type="model",
|
repo_type="model",
|
||||||
allow_patterns=["*token*"],
|
allow_patterns=["*token*", "config.json"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -269,7 +285,19 @@ def download_llama3_8b_instruct_model_fixture():
|
|||||||
def download_phi_35_mini_model_fixture():
|
def download_phi_35_mini_model_fixture():
|
||||||
# download the tokenizer only
|
# download the tokenizer only
|
||||||
snapshot_download_w_retry(
|
snapshot_download_w_retry(
|
||||||
"microsoft/Phi-3.5-mini-instruct", repo_type="model", allow_patterns=["*token*"]
|
"microsoft/Phi-3.5-mini-instruct",
|
||||||
|
repo_type="model",
|
||||||
|
allow_patterns=["*token*", "config.json"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
|
def download_phi_4_reasoning_model_fixture():
|
||||||
|
# download the tokenizer only
|
||||||
|
snapshot_download_w_retry(
|
||||||
|
"microsoft/Phi-4-reasoning",
|
||||||
|
repo_type="model",
|
||||||
|
allow_patterns=["*token*", "config.json"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -279,7 +307,7 @@ def download_phi_3_medium_model_fixture():
|
|||||||
snapshot_download_w_retry(
|
snapshot_download_w_retry(
|
||||||
"microsoft/Phi-3-medium-128k-instruct",
|
"microsoft/Phi-3-medium-128k-instruct",
|
||||||
repo_type="model",
|
repo_type="model",
|
||||||
allow_patterns=["*token*"],
|
allow_patterns=["*token*", "config.json"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -562,6 +590,8 @@ def test_load_fixtures(
|
|||||||
download_mhenrichsen_alpaca_2k_dataset,
|
download_mhenrichsen_alpaca_2k_dataset,
|
||||||
download_mhenrichsen_alpaca_2k_w_revision_dataset,
|
download_mhenrichsen_alpaca_2k_w_revision_dataset,
|
||||||
download_mlabonne_finetome_100k_dataset,
|
download_mlabonne_finetome_100k_dataset,
|
||||||
|
download_argilla_ultrafeedback_binarized_preferences_cleaned_dataset,
|
||||||
|
download_argilla_ultrafeedback_binarized_preferences_cleaned_kto_dataset,
|
||||||
download_argilla_distilabel_capybara_dpo_7k_binarized_dataset,
|
download_argilla_distilabel_capybara_dpo_7k_binarized_dataset,
|
||||||
download_arcee_ai_distilabel_intel_orca_dpo_pairs_dataset,
|
download_arcee_ai_distilabel_intel_orca_dpo_pairs_dataset,
|
||||||
download_argilla_dpo_pairs_dataset,
|
download_argilla_dpo_pairs_dataset,
|
||||||
@@ -573,6 +603,7 @@ def test_load_fixtures(
|
|||||||
download_llama3_8b_instruct_model_fixture,
|
download_llama3_8b_instruct_model_fixture,
|
||||||
download_phi_35_mini_model_fixture,
|
download_phi_35_mini_model_fixture,
|
||||||
download_phi_3_medium_model_fixture,
|
download_phi_3_medium_model_fixture,
|
||||||
|
download_phi_4_reasoning_model_fixture,
|
||||||
download_mistral_7b_model_fixture,
|
download_mistral_7b_model_fixture,
|
||||||
download_gemma_2b_model_fixture,
|
download_gemma_2b_model_fixture,
|
||||||
download_gemma2_9b_model_fixture,
|
download_gemma2_9b_model_fixture,
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ def fixture_base_cfg():
|
|||||||
# Checkpointing and saving
|
# Checkpointing and saving
|
||||||
"save_steps": 100,
|
"save_steps": 100,
|
||||||
"output_dir": "./model-out",
|
"output_dir": "./model-out",
|
||||||
"save_safetensors": True,
|
|
||||||
"save_total_limit": 4,
|
"save_total_limit": 4,
|
||||||
"save_only_model": False,
|
"save_only_model": False,
|
||||||
# Hardware/performance settings
|
# Hardware/performance settings
|
||||||
@@ -311,7 +310,6 @@ class TestHFRLTrainerBuilder:
|
|||||||
# KTO specific
|
# KTO specific
|
||||||
assert training_arguments.desirable_weight == 1.0
|
assert training_arguments.desirable_weight == 1.0
|
||||||
assert training_arguments.undesirable_weight == 1.0
|
assert training_arguments.undesirable_weight == 1.0
|
||||||
assert training_arguments.max_prompt_length == 512
|
|
||||||
|
|
||||||
def _write_rewards_file(self, rewards_dir: Path):
|
def _write_rewards_file(self, rewards_dir: Path):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from axolotl.utils import get_pytorch_version
|
|||||||
from axolotl.utils.config import normalize_config, prepare_plugins, validate_config
|
from axolotl.utils.config import normalize_config, prepare_plugins, validate_config
|
||||||
from axolotl.utils.dict import DictDefault
|
from axolotl.utils.dict import DictDefault
|
||||||
|
|
||||||
from ..utils import check_model_output_exists
|
from tests.e2e.utils import check_model_output_exists
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
@@ -39,7 +39,6 @@ def min_cfg(temp_dir):
|
|||||||
"optimizer": "adamw_torch_fused",
|
"optimizer": "adamw_torch_fused",
|
||||||
"output_dir": temp_dir,
|
"output_dir": temp_dir,
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"save_safetensors": True,
|
|
||||||
"max_steps": 10,
|
"max_steps": 10,
|
||||||
"bf16": "auto",
|
"bf16": "auto",
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
@@ -92,7 +91,6 @@ class TestCutCrossEntropyIntegration:
|
|||||||
"optimizer": "adamw_torch_fused",
|
"optimizer": "adamw_torch_fused",
|
||||||
"output_dir": temp_dir,
|
"output_dir": temp_dir,
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"save_safetensors": True,
|
|
||||||
"max_steps": 10,
|
"max_steps": 10,
|
||||||
"bf16": "auto",
|
"bf16": "auto",
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ class FP8IntegrationTestCase:
|
|||||||
"sample_packing": True,
|
"sample_packing": True,
|
||||||
"fp8": True,
|
"fp8": True,
|
||||||
"torch_compile": True,
|
"torch_compile": True,
|
||||||
"save_safetensors": True,
|
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from axolotl.train import train
|
|||||||
from axolotl.utils.config import normalize_config, prepare_plugins, validate_config
|
from axolotl.utils.config import normalize_config, prepare_plugins, validate_config
|
||||||
from axolotl.utils.dict import DictDefault
|
from axolotl.utils.dict import DictDefault
|
||||||
|
|
||||||
from ..utils import check_model_output_exists
|
from tests.e2e.utils import check_model_output_exists
|
||||||
|
|
||||||
|
|
||||||
class LogHooksPlugin(BasePlugin):
|
class LogHooksPlugin(BasePlugin):
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ def min_cfg(temp_dir):
|
|||||||
},
|
},
|
||||||
"max_steps": 5,
|
"max_steps": 5,
|
||||||
"output_dir": temp_dir,
|
"output_dir": temp_dir,
|
||||||
"save_safetensors": True,
|
|
||||||
"use_tensorboard": True,
|
"use_tensorboard": True,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ class LigerIntegrationTestCase:
|
|||||||
"learning_rate": 0.00001,
|
"learning_rate": 0.00001,
|
||||||
"optimizer": "adamw_torch_fused",
|
"optimizer": "adamw_torch_fused",
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"save_safetensors": True,
|
|
||||||
"bf16": "auto",
|
"bf16": "auto",
|
||||||
"max_steps": 5,
|
"max_steps": 5,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
@@ -99,7 +98,6 @@ class LigerIntegrationTestCase:
|
|||||||
"learning_rate": 0.00001,
|
"learning_rate": 0.00001,
|
||||||
"optimizer": "adamw_torch_fused",
|
"optimizer": "adamw_torch_fused",
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"save_safetensors": True,
|
|
||||||
"bf16": "auto",
|
"bf16": "auto",
|
||||||
"max_steps": 5,
|
"max_steps": 5,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ class TestLLMCompressorIntegration:
|
|||||||
"learning_rate": 1e-5,
|
"learning_rate": 1e-5,
|
||||||
"optimizer": "adamw_torch_fused",
|
"optimizer": "adamw_torch_fused",
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"save_safetensors": True,
|
|
||||||
"bf16": "auto",
|
"bf16": "auto",
|
||||||
"max_steps": 5,
|
"max_steps": 5,
|
||||||
"llmcompressor": {
|
"llmcompressor": {
|
||||||
|
|||||||
538
tests/e2e/multigpu/solo/test_gdpo.py
Normal file
538
tests/e2e/multigpu/solo/test_gdpo.py
Normal file
@@ -0,0 +1,538 @@
|
|||||||
|
"""
|
||||||
|
GDPO test suite
|
||||||
|
|
||||||
|
GDPO uses TRL's multi_objective_aggregation="normalize_then_sum" for
|
||||||
|
per-reward normalization in multi-reward RL training.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import yaml
|
||||||
|
from accelerate.test_utils import execute_subprocess_async
|
||||||
|
from transformers.testing_utils import get_torch_dist_unique_port
|
||||||
|
|
||||||
|
from axolotl.utils.dict import DictDefault
|
||||||
|
|
||||||
|
from tests.e2e.multigpu.solo.test_grpo import recursive_kill, start_vllm
|
||||||
|
from tests.e2e.utils import require_vllm
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip(reason="flaky vllm tests in modal")
|
||||||
|
class TestGDPO:
|
||||||
|
"""Test case for GDPO training using TRL's native multi-objective aggregation."""
|
||||||
|
|
||||||
|
def _utils_write_yaml_and_rewards(self, cfg, temp_dir, suffix=""):
|
||||||
|
Path(temp_dir).mkdir(parents=True, exist_ok=True)
|
||||||
|
with open(Path(temp_dir) / "config.yaml", "w", encoding="utf-8") as fout:
|
||||||
|
fout.write(yaml.dump(cfg.to_dict(), Dumper=yaml.Dumper))
|
||||||
|
with open(f"rewards_gdpo_{suffix}.py", "w", encoding="utf-8") as fout:
|
||||||
|
fout.write(
|
||||||
|
"""import random
|
||||||
|
|
||||||
|
def format_reward(prompts, completions, **kwargs) -> list[float]:
|
||||||
|
return [1.0 if len(c) > 10 else 0.0 for c in completions]
|
||||||
|
|
||||||
|
def correctness_reward(prompts, completions, **kwargs) -> list[float]:
|
||||||
|
return [random.uniform(-1, 3) for _ in completions]
|
||||||
|
|
||||||
|
def safety_reward(prompts, completions, **kwargs) -> list[float]:
|
||||||
|
return [1.0 if 'error' not in c.lower() else 0.0 for c in completions]
|
||||||
|
|
||||||
|
def single_reward(prompts, completions, **kwargs) -> list[float]:
|
||||||
|
return [random.uniform(0, 1) for _ in completions]
|
||||||
|
|
||||||
|
def oai_gsm8k_transform(cfg, *args, **kwargs):
|
||||||
|
def transform_fn(example, tokenizer=None):
|
||||||
|
label = example["answer"].split("####")[-1].strip().replace(",", "")
|
||||||
|
return {
|
||||||
|
"prompt": [{"role": "user", "content": example["question"]}],
|
||||||
|
"answer": label,
|
||||||
|
}
|
||||||
|
return transform_fn, {"remove_columns": ["question"]}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("num_gpus", [1, 2])
|
||||||
|
@require_vllm
|
||||||
|
def test_gdpo_multi_reward_lora(self, temp_dir, num_gpus):
|
||||||
|
"""Test GDPO with multiple reward functions using LoRA."""
|
||||||
|
rnd_suffix = str(random.randint(1000, 9999))
|
||||||
|
cfg = DictDefault(
|
||||||
|
{
|
||||||
|
"base_model": "HuggingFaceTB/SmolLM2-135M",
|
||||||
|
"chat_template": "llama3",
|
||||||
|
"rl": "gdpo",
|
||||||
|
"trl": {
|
||||||
|
"beta": 0.001,
|
||||||
|
"max_completion_length": 256,
|
||||||
|
"use_vllm": True,
|
||||||
|
"num_generations": 4,
|
||||||
|
"reward_funcs": [
|
||||||
|
f"rewards_gdpo_{rnd_suffix}.format_reward",
|
||||||
|
f"rewards_gdpo_{rnd_suffix}.correctness_reward",
|
||||||
|
],
|
||||||
|
"reward_weights": [1.0, 2.0],
|
||||||
|
"scale_rewards": True,
|
||||||
|
},
|
||||||
|
"vllm": {
|
||||||
|
"max_model_len": 800,
|
||||||
|
"enable_prefix_caching": True,
|
||||||
|
},
|
||||||
|
"datasets": [
|
||||||
|
{
|
||||||
|
"path": "openai/gsm8k",
|
||||||
|
"name": "main",
|
||||||
|
"type": f"rewards_gdpo_{rnd_suffix}.oai_gsm8k_transform",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"adapter": "lora",
|
||||||
|
"lora_r": 8,
|
||||||
|
"lora_alpha": 16,
|
||||||
|
"lora_dropout": 0.05,
|
||||||
|
"lora_target_linear": True,
|
||||||
|
"flash_attention": True,
|
||||||
|
"sequence_len": 1024,
|
||||||
|
"special_tokens": {
|
||||||
|
"pad_token": "<|endoftext|>",
|
||||||
|
},
|
||||||
|
"max_steps": 3,
|
||||||
|
"num_epochs": 1,
|
||||||
|
"micro_batch_size": 4,
|
||||||
|
"gradient_accumulation_steps": 2,
|
||||||
|
"warmup_steps": 10,
|
||||||
|
"val_set_size": 0.0,
|
||||||
|
"output_dir": temp_dir,
|
||||||
|
"learning_rate": 0.0001,
|
||||||
|
"optimizer": "adamw_torch_fused",
|
||||||
|
"lr_scheduler": "cosine",
|
||||||
|
"save_safetensors": True,
|
||||||
|
"bf16": "auto",
|
||||||
|
"use_tensorboard": True,
|
||||||
|
"save_first_step": False,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self._utils_write_yaml_and_rewards(cfg, temp_dir, suffix=rnd_suffix)
|
||||||
|
|
||||||
|
current_env = os.environ.copy()
|
||||||
|
env = {
|
||||||
|
"NCCL_P2P_LEVEL": "LOC",
|
||||||
|
**current_env,
|
||||||
|
"CUDA_VISIBLE_DEVICES": "1",
|
||||||
|
}
|
||||||
|
vllm_process = start_vllm(
|
||||||
|
cfg.base_model,
|
||||||
|
env=env,
|
||||||
|
quiet=True,
|
||||||
|
wait=300,
|
||||||
|
gpu_memory_utilization=0.15,
|
||||||
|
max_model_len=cfg.vllm.max_model_len,
|
||||||
|
enable_prefix_caching=cfg.vllm.enable_prefix_caching,
|
||||||
|
host="0.0.0.0",
|
||||||
|
port=8000,
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
execute_subprocess_async(
|
||||||
|
[
|
||||||
|
"axolotl",
|
||||||
|
"train",
|
||||||
|
str(Path(temp_dir) / "config.yaml"),
|
||||||
|
"--num-processes",
|
||||||
|
str(num_gpus),
|
||||||
|
"--main-process-port",
|
||||||
|
f"{get_torch_dist_unique_port()}",
|
||||||
|
],
|
||||||
|
env={
|
||||||
|
"NCCL_P2P_LEVEL": "LOC",
|
||||||
|
"NCCL_DEBUG": "INFO",
|
||||||
|
**current_env,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
recursive_kill(vllm_process)
|
||||||
|
|
||||||
|
@require_vllm
|
||||||
|
def test_gdpo_three_rewards(self, temp_dir):
|
||||||
|
"""Test GDPO with three reward functions (format, correctness, safety)."""
|
||||||
|
rnd_suffix = str(random.randint(1000, 9999))
|
||||||
|
cfg = DictDefault(
|
||||||
|
{
|
||||||
|
"base_model": "HuggingFaceTB/SmolLM2-135M",
|
||||||
|
"chat_template": "llama3",
|
||||||
|
"rl": "gdpo",
|
||||||
|
"trl": {
|
||||||
|
"beta": 0.001,
|
||||||
|
"max_completion_length": 256,
|
||||||
|
"use_vllm": True,
|
||||||
|
"num_generations": 4,
|
||||||
|
"reward_funcs": [
|
||||||
|
f"rewards_gdpo_{rnd_suffix}.format_reward",
|
||||||
|
f"rewards_gdpo_{rnd_suffix}.correctness_reward",
|
||||||
|
f"rewards_gdpo_{rnd_suffix}.safety_reward",
|
||||||
|
],
|
||||||
|
"reward_weights": [1.0, 2.0, 1.5],
|
||||||
|
},
|
||||||
|
"vllm": {
|
||||||
|
"max_model_len": 800,
|
||||||
|
"enable_prefix_caching": True,
|
||||||
|
},
|
||||||
|
"datasets": [
|
||||||
|
{
|
||||||
|
"path": "openai/gsm8k",
|
||||||
|
"name": "main",
|
||||||
|
"type": f"rewards_gdpo_{rnd_suffix}.oai_gsm8k_transform",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"adapter": "lora",
|
||||||
|
"lora_r": 8,
|
||||||
|
"lora_alpha": 16,
|
||||||
|
"lora_dropout": 0.05,
|
||||||
|
"lora_target_linear": True,
|
||||||
|
"flash_attention": True,
|
||||||
|
"sequence_len": 1024,
|
||||||
|
"special_tokens": {
|
||||||
|
"pad_token": "<|endoftext|>",
|
||||||
|
},
|
||||||
|
"max_steps": 3,
|
||||||
|
"num_epochs": 1,
|
||||||
|
"micro_batch_size": 4,
|
||||||
|
"gradient_accumulation_steps": 2,
|
||||||
|
"warmup_steps": 10,
|
||||||
|
"val_set_size": 0.0,
|
||||||
|
"output_dir": temp_dir,
|
||||||
|
"learning_rate": 0.0001,
|
||||||
|
"optimizer": "adamw_torch_fused",
|
||||||
|
"lr_scheduler": "cosine",
|
||||||
|
"save_safetensors": True,
|
||||||
|
"bf16": "auto",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self._utils_write_yaml_and_rewards(cfg, temp_dir, suffix=rnd_suffix)
|
||||||
|
|
||||||
|
current_env = os.environ.copy()
|
||||||
|
env = {
|
||||||
|
"NCCL_P2P_LEVEL": "LOC",
|
||||||
|
**current_env,
|
||||||
|
"CUDA_VISIBLE_DEVICES": "1",
|
||||||
|
}
|
||||||
|
vllm_process = start_vllm(
|
||||||
|
cfg.base_model,
|
||||||
|
env=env,
|
||||||
|
quiet=True,
|
||||||
|
wait=300,
|
||||||
|
gpu_memory_utilization=0.15,
|
||||||
|
max_model_len=cfg.vllm.max_model_len,
|
||||||
|
enable_prefix_caching=cfg.vllm.enable_prefix_caching,
|
||||||
|
host="0.0.0.0",
|
||||||
|
port=8000,
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
execute_subprocess_async(
|
||||||
|
[
|
||||||
|
"axolotl",
|
||||||
|
"train",
|
||||||
|
str(Path(temp_dir) / "config.yaml"),
|
||||||
|
"--num-processes",
|
||||||
|
"1",
|
||||||
|
"--main-process-port",
|
||||||
|
f"{get_torch_dist_unique_port()}",
|
||||||
|
],
|
||||||
|
env={
|
||||||
|
"NCCL_P2P_LEVEL": "LOC",
|
||||||
|
"NCCL_DEBUG": "INFO",
|
||||||
|
**current_env,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
recursive_kill(vllm_process)
|
||||||
|
|
||||||
|
@require_vllm
|
||||||
|
def test_gdpo_single_reward_fallback(self, temp_dir):
|
||||||
|
"""Test GDPO with single reward."""
|
||||||
|
rnd_suffix = str(random.randint(1000, 9999))
|
||||||
|
cfg = DictDefault(
|
||||||
|
{
|
||||||
|
"base_model": "HuggingFaceTB/SmolLM2-135M",
|
||||||
|
"chat_template": "llama3",
|
||||||
|
"rl": "gdpo",
|
||||||
|
"trl": {
|
||||||
|
"beta": 0.001,
|
||||||
|
"max_completion_length": 256,
|
||||||
|
"use_vllm": True,
|
||||||
|
"num_generations": 4,
|
||||||
|
"reward_funcs": [
|
||||||
|
f"rewards_gdpo_{rnd_suffix}.single_reward",
|
||||||
|
],
|
||||||
|
"reward_weights": [1.0],
|
||||||
|
},
|
||||||
|
"vllm": {
|
||||||
|
"max_model_len": 800,
|
||||||
|
"enable_prefix_caching": True,
|
||||||
|
},
|
||||||
|
"datasets": [
|
||||||
|
{
|
||||||
|
"path": "openai/gsm8k",
|
||||||
|
"name": "main",
|
||||||
|
"type": f"rewards_gdpo_{rnd_suffix}.oai_gsm8k_transform",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"adapter": "lora",
|
||||||
|
"lora_r": 8,
|
||||||
|
"lora_alpha": 16,
|
||||||
|
"lora_dropout": 0.05,
|
||||||
|
"lora_target_linear": True,
|
||||||
|
"flash_attention": True,
|
||||||
|
"sequence_len": 1024,
|
||||||
|
"special_tokens": {
|
||||||
|
"pad_token": "<|endoftext|>",
|
||||||
|
},
|
||||||
|
"max_steps": 3,
|
||||||
|
"num_epochs": 1,
|
||||||
|
"micro_batch_size": 4,
|
||||||
|
"gradient_accumulation_steps": 2,
|
||||||
|
"warmup_steps": 10,
|
||||||
|
"val_set_size": 0.0,
|
||||||
|
"output_dir": temp_dir,
|
||||||
|
"learning_rate": 0.0001,
|
||||||
|
"optimizer": "adamw_torch_fused",
|
||||||
|
"lr_scheduler": "cosine",
|
||||||
|
"save_safetensors": True,
|
||||||
|
"bf16": "auto",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self._utils_write_yaml_and_rewards(cfg, temp_dir, suffix=rnd_suffix)
|
||||||
|
|
||||||
|
current_env = os.environ.copy()
|
||||||
|
env = {
|
||||||
|
"NCCL_P2P_LEVEL": "LOC",
|
||||||
|
**current_env,
|
||||||
|
"CUDA_VISIBLE_DEVICES": "1",
|
||||||
|
}
|
||||||
|
vllm_process = start_vllm(
|
||||||
|
cfg.base_model,
|
||||||
|
env=env,
|
||||||
|
quiet=True,
|
||||||
|
wait=300,
|
||||||
|
gpu_memory_utilization=0.15,
|
||||||
|
max_model_len=cfg.vllm.max_model_len,
|
||||||
|
enable_prefix_caching=cfg.vllm.enable_prefix_caching,
|
||||||
|
host="0.0.0.0",
|
||||||
|
port=8000,
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
execute_subprocess_async(
|
||||||
|
[
|
||||||
|
"axolotl",
|
||||||
|
"train",
|
||||||
|
str(Path(temp_dir) / "config.yaml"),
|
||||||
|
"--num-processes",
|
||||||
|
"1",
|
||||||
|
"--main-process-port",
|
||||||
|
f"{get_torch_dist_unique_port()}",
|
||||||
|
],
|
||||||
|
env={
|
||||||
|
"NCCL_P2P_LEVEL": "LOC",
|
||||||
|
"NCCL_DEBUG": "INFO",
|
||||||
|
**current_env,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
recursive_kill(vllm_process)
|
||||||
|
|
||||||
|
@require_vllm
|
||||||
|
def test_gdpo_fft(self, temp_dir):
|
||||||
|
"""Test GDPO with full fine-tuning (no adapter)."""
|
||||||
|
rnd_suffix = str(random.randint(1000, 9999))
|
||||||
|
cfg = DictDefault(
|
||||||
|
{
|
||||||
|
"base_model": "HuggingFaceTB/SmolLM2-135M",
|
||||||
|
"chat_template": "llama3",
|
||||||
|
"rl": "gdpo",
|
||||||
|
"trl": {
|
||||||
|
"beta": 0.001,
|
||||||
|
"max_completion_length": 256,
|
||||||
|
"use_vllm": True,
|
||||||
|
"num_generations": 4,
|
||||||
|
"reward_funcs": [
|
||||||
|
f"rewards_gdpo_{rnd_suffix}.format_reward",
|
||||||
|
f"rewards_gdpo_{rnd_suffix}.correctness_reward",
|
||||||
|
],
|
||||||
|
"reward_weights": [1.0, 2.0],
|
||||||
|
},
|
||||||
|
"vllm": {
|
||||||
|
"max_model_len": 800,
|
||||||
|
"enable_prefix_caching": True,
|
||||||
|
},
|
||||||
|
"datasets": [
|
||||||
|
{
|
||||||
|
"path": "openai/gsm8k",
|
||||||
|
"name": "main",
|
||||||
|
"type": f"rewards_gdpo_{rnd_suffix}.oai_gsm8k_transform",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
# No adapter - full fine-tuning
|
||||||
|
"flash_attention": True,
|
||||||
|
"sequence_len": 1024,
|
||||||
|
"special_tokens": {
|
||||||
|
"pad_token": "<|endoftext|>",
|
||||||
|
},
|
||||||
|
"max_steps": 3,
|
||||||
|
"num_epochs": 1,
|
||||||
|
"micro_batch_size": 4,
|
||||||
|
"gradient_accumulation_steps": 2,
|
||||||
|
"warmup_steps": 10,
|
||||||
|
"val_set_size": 0.0,
|
||||||
|
"output_dir": temp_dir,
|
||||||
|
"learning_rate": 0.0001,
|
||||||
|
"optimizer": "adamw_torch_fused",
|
||||||
|
"lr_scheduler": "cosine",
|
||||||
|
"save_safetensors": True,
|
||||||
|
"bf16": "auto",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self._utils_write_yaml_and_rewards(cfg, temp_dir, suffix=rnd_suffix)
|
||||||
|
|
||||||
|
current_env = os.environ.copy()
|
||||||
|
env = {
|
||||||
|
"NCCL_P2P_LEVEL": "LOC",
|
||||||
|
**current_env,
|
||||||
|
"CUDA_VISIBLE_DEVICES": "1",
|
||||||
|
}
|
||||||
|
vllm_process = start_vllm(
|
||||||
|
cfg.base_model,
|
||||||
|
env=env,
|
||||||
|
quiet=True,
|
||||||
|
wait=300,
|
||||||
|
gpu_memory_utilization=0.15,
|
||||||
|
max_model_len=cfg.vllm.max_model_len,
|
||||||
|
enable_prefix_caching=cfg.vllm.enable_prefix_caching,
|
||||||
|
host="0.0.0.0",
|
||||||
|
port=8000,
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
execute_subprocess_async(
|
||||||
|
[
|
||||||
|
"axolotl",
|
||||||
|
"train",
|
||||||
|
str(Path(temp_dir) / "config.yaml"),
|
||||||
|
"--num-processes",
|
||||||
|
"1",
|
||||||
|
"--main-process-port",
|
||||||
|
f"{get_torch_dist_unique_port()}",
|
||||||
|
],
|
||||||
|
env={
|
||||||
|
"NCCL_P2P_LEVEL": "LOC",
|
||||||
|
"NCCL_DEBUG": "INFO",
|
||||||
|
**current_env,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
recursive_kill(vllm_process)
|
||||||
|
|
||||||
|
@require_vllm
|
||||||
|
def test_gdpo_sequence_parallel(self, temp_dir):
|
||||||
|
"""Test GDPO with sequence parallelism."""
|
||||||
|
rnd_suffix = str(random.randint(1000, 9999))
|
||||||
|
cfg = DictDefault(
|
||||||
|
{
|
||||||
|
"base_model": "HuggingFaceTB/SmolLM2-135M",
|
||||||
|
"chat_template": "llama3",
|
||||||
|
"rl": "gdpo",
|
||||||
|
"context_parallel_size": 2,
|
||||||
|
"trl": {
|
||||||
|
"beta": 0.001,
|
||||||
|
"max_completion_length": 256,
|
||||||
|
"use_vllm": True,
|
||||||
|
"num_generations": 4,
|
||||||
|
"reward_funcs": [
|
||||||
|
f"rewards_gdpo_{rnd_suffix}.format_reward",
|
||||||
|
f"rewards_gdpo_{rnd_suffix}.correctness_reward",
|
||||||
|
],
|
||||||
|
"reward_weights": [1.0, 2.0],
|
||||||
|
},
|
||||||
|
"vllm": {
|
||||||
|
"max_model_len": 800,
|
||||||
|
"enable_prefix_caching": True,
|
||||||
|
},
|
||||||
|
"datasets": [
|
||||||
|
{
|
||||||
|
"path": "openai/gsm8k",
|
||||||
|
"name": "main",
|
||||||
|
"type": f"rewards_gdpo_{rnd_suffix}.oai_gsm8k_transform",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"adapter": "lora",
|
||||||
|
"lora_r": 8,
|
||||||
|
"lora_alpha": 16,
|
||||||
|
"lora_dropout": 0.05,
|
||||||
|
"lora_target_linear": True,
|
||||||
|
"flash_attention": True,
|
||||||
|
"sequence_len": 1024,
|
||||||
|
"special_tokens": {
|
||||||
|
"pad_token": "<|endoftext|>",
|
||||||
|
},
|
||||||
|
"max_steps": 3,
|
||||||
|
"num_epochs": 1,
|
||||||
|
"micro_batch_size": 4,
|
||||||
|
"gradient_accumulation_steps": 2,
|
||||||
|
"warmup_steps": 10,
|
||||||
|
"val_set_size": 0.0,
|
||||||
|
"output_dir": temp_dir,
|
||||||
|
"dataset_prepared_path": temp_dir + "/last_run_prepared",
|
||||||
|
"learning_rate": 0.0001,
|
||||||
|
"optimizer": "adamw_torch_fused",
|
||||||
|
"lr_scheduler": "cosine",
|
||||||
|
"save_safetensors": True,
|
||||||
|
"bf16": "auto",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self._utils_write_yaml_and_rewards(cfg, temp_dir, suffix=rnd_suffix)
|
||||||
|
|
||||||
|
current_env = os.environ.copy()
|
||||||
|
env = {
|
||||||
|
"NCCL_P2P_LEVEL": "LOC",
|
||||||
|
**current_env,
|
||||||
|
"CUDA_VISIBLE_DEVICES": "1",
|
||||||
|
}
|
||||||
|
vllm_process = start_vllm(
|
||||||
|
cfg.base_model,
|
||||||
|
env=env,
|
||||||
|
quiet=True,
|
||||||
|
wait=300,
|
||||||
|
gpu_memory_utilization=0.15,
|
||||||
|
max_model_len=cfg.vllm.max_model_len,
|
||||||
|
enable_prefix_caching=cfg.vllm.enable_prefix_caching,
|
||||||
|
host="0.0.0.0",
|
||||||
|
port=8000,
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
execute_subprocess_async(
|
||||||
|
[
|
||||||
|
"axolotl",
|
||||||
|
"train",
|
||||||
|
str(Path(temp_dir) / "config.yaml"),
|
||||||
|
"--num-processes",
|
||||||
|
"2",
|
||||||
|
"--main-process-port",
|
||||||
|
f"{get_torch_dist_unique_port()}",
|
||||||
|
],
|
||||||
|
env={
|
||||||
|
"NCCL_P2P_LEVEL": "LOC",
|
||||||
|
"NCCL_DEBUG": "INFO",
|
||||||
|
**current_env,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
recursive_kill(vllm_process)
|
||||||
@@ -220,7 +220,6 @@ def oai_gsm8k_transform(cfg, *args, **kwargs):
|
|||||||
"learning_rate": 0.0001,
|
"learning_rate": 0.0001,
|
||||||
"optimizer": "adamw_torch_fused",
|
"optimizer": "adamw_torch_fused",
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"save_safetensors": True,
|
|
||||||
"bf16": "auto",
|
"bf16": "auto",
|
||||||
"use_tensorboard": True,
|
"use_tensorboard": True,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
@@ -315,7 +314,6 @@ def oai_gsm8k_transform(cfg, *args, **kwargs):
|
|||||||
"learning_rate": 0.0001,
|
"learning_rate": 0.0001,
|
||||||
"optimizer": "adamw_torch_fused",
|
"optimizer": "adamw_torch_fused",
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"save_safetensors": True,
|
|
||||||
"bf16": "auto",
|
"bf16": "auto",
|
||||||
"use_tensorboard": True,
|
"use_tensorboard": True,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
@@ -408,7 +406,6 @@ def oai_gsm8k_transform(cfg, *args, **kwargs):
|
|||||||
"learning_rate": 0.0001,
|
"learning_rate": 0.0001,
|
||||||
"optimizer": "adamw_torch_fused",
|
"optimizer": "adamw_torch_fused",
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"save_safetensors": True,
|
|
||||||
"bf16": "auto",
|
"bf16": "auto",
|
||||||
"use_tensorboard": True,
|
"use_tensorboard": True,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from transformers.testing_utils import get_torch_dist_unique_port
|
|||||||
|
|
||||||
from axolotl.utils.dict import DictDefault
|
from axolotl.utils.dict import DictDefault
|
||||||
|
|
||||||
from tests.e2e.utils import most_recent_subdir, require_hopper, require_torch_2_7_0
|
from tests.e2e.utils import most_recent_subdir, require_torch_2_7_0, supports_fp8
|
||||||
|
|
||||||
AXOLOTL_ROOT = Path(__file__).parent.parent.parent.parent
|
AXOLOTL_ROOT = Path(__file__).parent.parent.parent.parent
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ class TestFP8FSDP2:
|
|||||||
"""Test class for FP8 mixed precision with FSDP2 functionality."""
|
"""Test class for FP8 mixed precision with FSDP2 functionality."""
|
||||||
|
|
||||||
@require_torch_2_7_0
|
@require_torch_2_7_0
|
||||||
@require_hopper
|
@supports_fp8
|
||||||
def test_fp8_fsdp2_smoke(self, temp_dir):
|
def test_fp8_fsdp2_smoke(self, temp_dir):
|
||||||
"""Smoke test for 2-GPU FP8 + torch.compile + FSDP2 training"""
|
"""Smoke test for 2-GPU FP8 + torch.compile + FSDP2 training"""
|
||||||
cfg = DictDefault(
|
cfg = DictDefault(
|
||||||
@@ -94,7 +94,6 @@ class TestFP8FSDP2:
|
|||||||
"reshard_after_forward": True,
|
"reshard_after_forward": True,
|
||||||
},
|
},
|
||||||
"use_tensorboard": True,
|
"use_tensorboard": True,
|
||||||
"save_safetensors": True,
|
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -244,6 +244,7 @@ class TestFSDP1:
|
|||||||
|
|
||||||
verify_training_success(temp_dir)
|
verify_training_success(temp_dir)
|
||||||
|
|
||||||
|
@pytest.mark.skip("broken in transformers v5")
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"adapter_config",
|
"adapter_config",
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -150,6 +150,10 @@ class TestFSDP2:
|
|||||||
},
|
},
|
||||||
"use_tensorboard": True,
|
"use_tensorboard": True,
|
||||||
"bf16": True,
|
"bf16": True,
|
||||||
|
# explicitly disable LORA kernels, as they may be auto-enabled
|
||||||
|
"lora_mlp_kernel": False,
|
||||||
|
"lora_qkv_kernel": False,
|
||||||
|
"lora_o_kernel": False,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ def download_model():
|
|||||||
snapshot_download("axolotl-mirrors/gemma-3-4b-pt", repo_type="model")
|
snapshot_download("axolotl-mirrors/gemma-3-4b-pt", repo_type="model")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip(reason="FIXME")
|
||||||
class TestMultiGPUGemma3:
|
class TestMultiGPUGemma3:
|
||||||
"""
|
"""
|
||||||
Test case for Gemma3 models using LoRA
|
Test case for Gemma3 models using LoRA
|
||||||
@@ -32,6 +33,7 @@ class TestMultiGPUGemma3:
|
|||||||
cfg = DictDefault(
|
cfg = DictDefault(
|
||||||
{
|
{
|
||||||
"base_model": "axolotl-mirrors/gemma-3-4b-pt",
|
"base_model": "axolotl-mirrors/gemma-3-4b-pt",
|
||||||
|
"unfrozen_parameters": ["model.language_model.*", "lm_head"],
|
||||||
"sequence_len": 2048,
|
"sequence_len": 2048,
|
||||||
"ddp_find_unused_parameters": True,
|
"ddp_find_unused_parameters": True,
|
||||||
"sample_packing": True,
|
"sample_packing": True,
|
||||||
|
|||||||
@@ -901,7 +901,6 @@ class TestMultiGPULlama:
|
|||||||
"flash_attention": True,
|
"flash_attention": True,
|
||||||
"sample_packing": True,
|
"sample_packing": True,
|
||||||
"bf16": True,
|
"bf16": True,
|
||||||
"save_safetensors": True,
|
|
||||||
# "deepspeed": str(AXOLOTL_ROOT / "deepspeed_configs/zero1.json"),
|
# "deepspeed": str(AXOLOTL_ROOT / "deepspeed_configs/zero1.json"),
|
||||||
"use_tensorboard": True,
|
"use_tensorboard": True,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ class TestActivationCheckpointing:
|
|||||||
"flash_attention": True,
|
"flash_attention": True,
|
||||||
"sample_packing": True,
|
"sample_packing": True,
|
||||||
"bf16": True,
|
"bf16": True,
|
||||||
"save_safetensors": True,
|
|
||||||
"gradient_checkpointing": gradient_checkpointing,
|
"gradient_checkpointing": gradient_checkpointing,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
"dataset_num_proc": 4,
|
"dataset_num_proc": 4,
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ class TestLlamaPeftEmbeddings:
|
|||||||
"flash_attention": True,
|
"flash_attention": True,
|
||||||
"sample_packing": False,
|
"sample_packing": False,
|
||||||
"bf16": "auto",
|
"bf16": "auto",
|
||||||
"save_safetensors": True,
|
|
||||||
"embeddings_skip_upcast": True,
|
"embeddings_skip_upcast": True,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ class TestResumeLlama:
|
|||||||
"save_total_limit": 5,
|
"save_total_limit": 5,
|
||||||
"max_steps": 15,
|
"max_steps": 15,
|
||||||
"use_tensorboard": True,
|
"use_tensorboard": True,
|
||||||
"save_safetensors": True,
|
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
"include_tkps": True,
|
"include_tkps": True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ class TestReLoraLlama(unittest.TestCase):
|
|||||||
"learning_rate": 0.00001,
|
"learning_rate": 0.00001,
|
||||||
"optimizer": "adamw_8bit",
|
"optimizer": "adamw_8bit",
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"save_safetensors": True,
|
|
||||||
"use_tensorboard": True,
|
"use_tensorboard": True,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ class TestActivationOffloading:
|
|||||||
"flash_attention": True,
|
"flash_attention": True,
|
||||||
"sample_packing": True,
|
"sample_packing": True,
|
||||||
"bf16": "auto",
|
"bf16": "auto",
|
||||||
"save_safetensors": True,
|
|
||||||
"gradient_checkpointing": True,
|
"gradient_checkpointing": True,
|
||||||
"activation_offloading": True,
|
"activation_offloading": True,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ class TestDeepseekV3:
|
|||||||
"optimizer": "adamw_bnb_8bit",
|
"optimizer": "adamw_bnb_8bit",
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"max_steps": 5,
|
"max_steps": 5,
|
||||||
"save_safetensors": True,
|
|
||||||
"bf16": True,
|
"bf16": True,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
}
|
}
|
||||||
@@ -113,7 +112,6 @@ class TestDeepseekV3:
|
|||||||
"optimizer": "adamw_bnb_8bit",
|
"optimizer": "adamw_bnb_8bit",
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"max_steps": 5,
|
"max_steps": 5,
|
||||||
"save_safetensors": True,
|
|
||||||
"bf16": True,
|
"bf16": True,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ class TestDiffusion:
|
|||||||
"optimizer": "adamw_torch",
|
"optimizer": "adamw_torch",
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"bf16": True,
|
"bf16": True,
|
||||||
"save_safetensors": True,
|
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
"logging_steps": 1,
|
"logging_steps": 1,
|
||||||
"eval_steps": 3,
|
"eval_steps": 3,
|
||||||
@@ -97,7 +96,6 @@ class TestDiffusion:
|
|||||||
"optimizer": "adamw_torch",
|
"optimizer": "adamw_torch",
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"bf16": True,
|
"bf16": True,
|
||||||
"save_safetensors": True,
|
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
"logging_steps": 1,
|
"logging_steps": 1,
|
||||||
"eval_steps": 2,
|
"eval_steps": 2,
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ class TestEmbeddingsLrScale(unittest.TestCase):
|
|||||||
"optimizer": "adamw_torch_fused",
|
"optimizer": "adamw_torch_fused",
|
||||||
"embedding_lr_scale": 0.5,
|
"embedding_lr_scale": 0.5,
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"save_safetensors": True,
|
|
||||||
"bf16": "auto",
|
"bf16": "auto",
|
||||||
"use_tensorboard": True,
|
"use_tensorboard": True,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
@@ -89,7 +88,6 @@ class TestEmbeddingsLrScale(unittest.TestCase):
|
|||||||
"optimizer": "adamw_torch_fused",
|
"optimizer": "adamw_torch_fused",
|
||||||
"embedding_lr": 0.000005,
|
"embedding_lr": 0.000005,
|
||||||
"lr_scheduler": "cosine",
|
"lr_scheduler": "cosine",
|
||||||
"save_safetensors": True,
|
|
||||||
"bf16": "auto",
|
"bf16": "auto",
|
||||||
"use_tensorboard": True,
|
"use_tensorboard": True,
|
||||||
"save_first_step": False,
|
"save_first_step": False,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user