Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4827dec
Add native Inkling 2 Mini attention LoRA training experiment
drisspg Nov 27, 2026
2231fa5
Validate native resume inputs and preserve packed expert precision
drisspg Nov 27, 2026
3dfc7ea
Match Inkling reference accumulation and guard the training data cursor
drisspg Nov 27, 2026
e1169c1
Restrict checked resume to literal corpus rows
drisspg Nov 27, 2026
4bbd936
Group packed Inkling experts and use FlexAttention on CUDA
drisspg Nov 27, 2026
f34f3a3
Keep Inkling checkpoint reads and writes bound to the intended source
drisspg Nov 27, 2026
ae55c05
Isolate each Inkling run from other checkpoints and retention
drisspg Nov 27, 2026
f7050f7
Reject FSDP-only training options in the single-device Inkling recipe
drisspg Nov 28, 2026
2e497ad
Reject checkpoint folder aliases before Inkling resume
drisspg Nov 28, 2026
ef52f06
Reject inactive FSDP settings in the Spark recipe
drisspg Nov 28, 2026
9455651
Compile Inkling expert quantization with eager division rounding
drisspg Nov 28, 2026
aac2832
Exercise Inkling FSDP validation without requiring a GPU
drisspg Nov 28, 2026
29d21be
Verify Inkling compiled quantizer executes on CUDA
drisspg Nov 28, 2026
17495f0
Train Inkling LoRA on multiple independent contexts per microbatch
drisspg Nov 28, 2026
5040900
Share Inkling row layout and refuse ambiguous data resumes
drisspg Nov 29, 2026
b985890
Keep Inkling training corpora outside checkpoint retention
drisspg Nov 29, 2026
0c91fd4
Keep Inkling training microbatches flat at the trainer boundary
drisspg Nov 29, 2026
6b9bba2
Protect linked Inkling snapshot shards from checkpoint retention
drisspg Nov 29, 2026
8ad5f82
Keep the Inkling recipe experiment-scoped and use one context layout
drisspg Nov 29, 2026
1fdd78d
Reject multi-rank Inkling launches before writing run state
drisspg Nov 29, 2026
b5f032a
Count logical Inkling expert weights from each configured layer
drisspg Nov 29, 2026
a3e780b
Keep Inkling resume within the verified run and clarify setup
drisspg Nov 29, 2026
3a8fb33
Simplify Inkling expert decoding and shorten the training guide
drisspg Nov 29, 2026
b3b5c19
Reuse TorchTitan mask predicates in Inkling attention
drisspg Nov 29, 2026
308a6f9
Simplify Inkling checkpoint verification and export bookkeeping
drisspg Nov 29, 2026
f7e2ab2
Document the Inkling scaled grouped forward migration
drisspg Nov 29, 2026
97d1c7f
Link upstream grouped NVFP4 support in the forward TODO
drisspg Nov 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/unit_test_cpu_inkling.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Inkling CPU Unit Test

on:
pull_request:
paths:
- 'torchtitan/experiments/inkling/**'
- 'torchtitan_recipes/inkling.py'
- '.github/workflows/unit_test_cpu_inkling.yaml'
push:
branches: [main]
paths:
- 'torchtitan/experiments/inkling/**'
- 'torchtitan_recipes/inkling.py'
- '.github/workflows/unit_test_cpu_inkling.yaml'

concurrency:
group: inkling-cpu-${{ github.ref }}
cancel-in-progress: true

permissions:
id-token: write
contents: read

jobs:
set-matrix:
uses: ./.github/workflows/set-matrix.yaml

test:
needs: set-matrix
uses: pytorch/test-infra/.github/workflows/linux_job_v3.yml@main
with:
runner: mt-l-x86iavx512-8-64
docker-image: 308535385114.dkr.ecr.us-east-1.amazonaws.com/torchtitan/torchtitan-ubuntu-22.04-clang12:${{ needs.set-matrix.outputs.docker-hash }}
repository: pytorch/torchtitan
script: |
set -eux
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
conda activate "${CONDA_ENV}"
pip install --force-reinstall --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu
pytest torchtitan/experiments/inkling/tests -v
1 change: 1 addition & 0 deletions torchtitan/experiments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ We provide this `experiments/` folder to host experiments that add significant v
| Experiment | Test Status | Owners |
| ----- | ----: | ----: |
| [graph_trainer](./graph_trainer/) | [![GraphTrainer 8 GPU Integration Tests](https://github.com/pytorch/torchtitan/actions/workflows/integration_test_8gpu_graph_trainer.yaml/badge.svg?branch=main)](https://github.com/pytorch/torchtitan/actions/workflows/integration_test_8gpu_graph_trainer.yaml?query=branch%3Amain) [![GraphTrainer H100 8 GPU Integration Tests](https://github.com/pytorch/torchtitan/actions/workflows/integration_test_8gpu_graph_trainer_h100.yaml/badge.svg?branch=main)](https://github.com/pytorch/torchtitan/actions/workflows/integration_test_8gpu_graph_trainer_h100.yaml?query=branch%3Amain) | [@SherlockNoMad](https://github.com/SherlockNoMad) |
| [inkling](./inkling/) | [Inkling CPU unit tests](https://github.com/pytorch/torchtitan/actions/workflows/unit_test_cpu_inkling.yaml) | [@drisspg](https://github.com/drisspg) |
| [torchft](./torchft/) | [![TorchFT 8 GPU Integration Tests](https://github.com/pytorch/torchtitan/actions/workflows/integration_test_8gpu_torchft.yaml/badge.svg?branch=main)](https://github.com/pytorch/torchtitan/actions/workflows/integration_test_8gpu_torchft.yaml?query=branch%3Amain) | [@d4l3k](https://github.com/d4l3k) [@tushar00jain](https://github.com/tushar00jain) |
| [transformers_modeling_backend](./transformers_modeling_backend/) | [![Transformers modeling backend 8 GPU Integration Tests](https://github.com/pytorch/torchtitan/actions/workflows/integration_test_8gpu_transformers_modeling_backend.yaml/badge.svg?branch=main)](https://github.com/pytorch/torchtitan/actions/workflows/integration_test_8gpu_transformers_modeling_backend.yaml?query=branch%3Amain) | [@HosseinKaviani-H](https://github.com/HosseinKaviani-H) |
73 changes: 73 additions & 0 deletions torchtitan/experiments/inkling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Inkling 2 Mini LoRA

Fine-tune the text model's query projections (`layers.*.attn.wq_du`) on one
DGX Spark. Only the FP32 LoRA adapters are trained; expert weights stay in
the checkpoint's NVFP4 and MXFP8 formats. Distributed training, full fine-tuning,
and vision inputs are not supported.

## Train

Follow the [TorchTitan installation instructions](../../../README.md#installation)
and activate that environment. From the checkout, download the tested snapshot:

```bash
export INKLING_SNAPSHOT="$(hf download thinkingmachines/Inkling-2-Mini --revision c9d028302cd0f035fdf8e7e91f089a4ce94d2195)"
```

Create an importable recipe, for example `inkling_run.py` in the checkout:

```python
import os
from pathlib import Path

from torchtitan_recipes.inkling import inkling_2_mini_lora


def spark():
checkpoint = Path(os.environ["INKLING_SNAPSHOT"])
config = inkling_2_mini_lora(
checkpoint=checkpoint, text=Path("train.txt"), seq_len=8, steps=10
)
return config
```

```bash
run="$HOME/checkpoints/inkling-query-lora"
torchrun --standalone --nproc-per-node=1 \
--module torchtitan.train --module inkling_run --config spark --output-dir "$run"
```

Use a UTF-8 text file with one document per line. To compile expert activation
quantization, set `config.model.local_compile.regions = ["inkling_quantize_input"]`
before returning the config. The default is eager. Compare runs in separate
output directories to avoid resuming an earlier run.

## Batching and resume

`contexts_per_microbatch=4` processes four independent contexts per forward
pass (default: one). With `config.dataloader.repeat = False` and no gradient
accumulation, set `steps = ceil(num_context_rows / contexts_per_microbatch)`.
Long documents can span several rows. Padding in the last microbatch does not
contribute to the loss.

Resume from the same output directory with a higher step limit. Keep the source
snapshot, corpus, context length, microbatch size, and repeat policy unchanged.
An exhausted finite corpus does not restart. Keep inputs outside
`$run/checkpoint`: retention deletes old step directories.

## Use the trained checkpoint in WarpDrive

The trainer merges the adapters into a new HF checkpoint at `$run/merged-step-N`
(about 19 GiB). Run WarpDrive against that directory from its own environment
(tested with attention-gym `5c2e8d594`). Training does not require WarpDrive.

```bash
cd ../attention-gym
.venv/bin/python -m attn_gym.warpdrive.examples.inkling_megakernel.chat \
--model "$run/merged-step-10" --backend megakernel-spec --verify-tokens 4 \
--prompt 'What is the capital of France?' --reasoning-effort low --max-new-tokens 64
```

The speculative backend requires `mtp.safetensors` in the merged directory.
If the source snapshot contains only the target model, use `--backend megakernel`
and omit `--verify-tokens 4`.
10 changes: 10 additions & 0 deletions torchtitan/experiments/inkling/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

from .flavors import build_model_config, MODEL_FLAVORS
from .model import InklingModel

__all__ = ["MODEL_FLAVORS", "InklingModel", "build_model_config"]
42 changes: 42 additions & 0 deletions torchtitan/experiments/inkling/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

from dataclasses import dataclass, replace

import grain.python as grain

from torchtitan.components.data import ConcatThenSplitPackingConfig, TextCollator
from torchtitan.components.data.types import DatasetBuildContext, DatasetIterationPolicy


@dataclass(frozen=True, kw_only=True, slots=True)
class InklingContextPackingConfig(ConcatThenSplitPackingConfig):
"""Pack one context at a time, independently of the microbatch token budget."""

def build(
self,
*,
context: DatasetBuildContext,
dataset_iteration_policy: DatasetIterationPolicy,
) -> grain.IterDataset:
return ConcatThenSplitPackingConfig.build(
self,
context=replace(
context, num_tokens_per_microbatch=context.max_context_length
),
dataset_iteration_policy=dataset_iteration_policy,
)


class InklingContextCollator(TextCollator):
"""Collect independently packed context rows into a flat token microbatch."""

@dataclass(kw_only=True, slots=True)
class Config(TextCollator.Config):
pass

def num_rows_per_microbatch(self) -> int:
return self._num_tokens_per_microbatch // self._max_context_length
Loading
Loading