Skip to content

Commit c479d48

Browse files
Merge branch 'main' into htn/fix-jax-splash-soft-cap
2 parents a56309f + 48c6b24 commit c479d48

58 files changed

Lines changed: 2436 additions & 596 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/CODEOWNERS

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
* @abhinavclemson @gobbleturk @khatwanimohit @bvandermoon @vipannalla @RissyRan @richjames0 @gagika @shralex @SurbhiJainUSC @hengtaoguo @A9isha @aireenmei @NuojCheng @jiangjy1982 @suexu1025 @NicoGrande @jesselu-google @dipannita08 @igorts-git @darisoy
1+
* @abhinavclemson @gobbleturk @khatwanimohit @bvandermoon @vipannalla @RissyRan @richjames0 @gagika @shralex @SurbhiJainUSC @hengtaoguo @A9isha @aireenmei @NuojCheng @jiangjy1982 @suexu1025 @NicoGrande @jesselu-google @dipannita08 @igorts-git @darisoy @xibinliu
22

33
# Model bring-up
44
src/maxtext/assets @parambole @shuningjin @RissyRan @suexu1025 @jiangjy1982 @gobbleturk @bvandermoon @gagika @shralex @richjames0 @NicoGrande
55
src/maxtext/configs/models @parambole @shuningjin @RissyRan @suexu1025 @jiangjy1982 @gobbleturk @bvandermoon @gagika @shralex @richjames0 @NicoGrande @jesselu-google @NuojCheng
66
src/maxtext/checkpoint_conversion @parambole @shuningjin @RissyRan @suexu1025 @jiangjy1982 @gobbleturk @bvandermoon @hengtaoguo @gagika @shralex @richjames0 @NicoGrande
7-
src/maxtext/layers @parambole @shuningjin @RissyRan @suexu1025 @jiangjy1982 @gobbleturk @bvandermoon @gagika @shralex @richjames0 @NicoGrande @jesselu-google @NuojCheng
8-
src/maxtext/models @parambole @shuningjin @RissyRan @suexu1025 @jiangjy1982 @gobbleturk @bvandermoon @gagika @shralex @richjames0 @NicoGrande @jesselu-google @NuojCheng
7+
src/maxtext/layers @parambole @shuningjin @RissyRan @suexu1025 @jiangjy1982 @gobbleturk @bvandermoon @gagika @shralex @richjames0 @NicoGrande @jesselu-google @NuojCheng @xibinliu
8+
src/maxtext/models @parambole @shuningjin @RissyRan @suexu1025 @jiangjy1982 @gobbleturk @bvandermoon @gagika @shralex @richjames0 @NicoGrande @jesselu-google @NuojCheng @xibinliu
99

1010
# Features
1111
src/maxtext/experimental/rl @A9isha @khatwanimohit @xuefgu @gagika @richjames0 @shralex @NicoGrande @darisoy
@@ -32,7 +32,7 @@ src/dependencies/ @bvandermoon @SurbhiJainUSC @parambole @richjames0 @shralex @d
3232
docs/ @jacoguzo @bvandermoon @SurbhiJainUSC @richjames0 @shralex @gobbleturk @RissyRan @gagika @A9isha @jiangjy1982 @vipannalla @darisoy
3333

3434
# Workflow files
35-
.github/workflows/ @gobbleturk @khatwanimohit @shralex @parambole @bvandermoon @richjames0 @darisoy
35+
.github/workflows/ @gobbleturk @khatwanimohit @shralex @parambole @bvandermoon @richjames0 @darisoy @xibinliu
3636

3737
# Benchmarking/Recipes
3838
benchmarks/ @SujeethJinesh @bvandermoon @richjames0 @shralex @vipannalla @mitalisi @RissyRan @shauryagup @NuojCheng @gobbleturk @khatwanimohit @Obliviour @notabee @suexu1025 @darisoy

.github/workflows/ci_pipeline.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,31 @@ jobs:
199199
is_scheduled_run: ${{ github.event_name == 'schedule' }}
200200
maxtext_sha: ${{ needs.build_and_upload_maxtext_package.outputs.maxtext_sha }}
201201

202+
setup-pathways-parameters:
203+
name: Setup Pathways Parameters
204+
runs-on: ubuntu-latest
205+
outputs:
206+
total_workers: ${{ steps.set-params.outputs.total_workers }}
207+
worker_groups: ${{ steps.set-params.outputs.worker_groups }}
208+
steps:
209+
- id: set-params
210+
name: Set Pathways Worker Parameters
211+
run: |
212+
# TPU worker constants
213+
TPU_UNIT_TOTAL_WORKERS=2
214+
TPU_UNIT_WORKER_GROUPS='[1, 2]'
215+
216+
echo "total_workers=${TPU_UNIT_TOTAL_WORKERS}" >> "$GITHUB_OUTPUT"
217+
echo "worker_groups=${TPU_UNIT_WORKER_GROUPS}" >> "$GITHUB_OUTPUT"
218+
202219
maxtext_tpu_pathways_unit_tests:
203-
needs: build_and_upload_maxtext_package
220+
needs: [build_and_upload_maxtext_package, setup-pathways-parameters]
204221
if: needs.analyze_code_changes.outputs.run_tests == 'true'
205222
uses: ./.github/workflows/run_pathways_tests.yml
206223
strategy:
207224
fail-fast: false
225+
matrix:
226+
group: ${{ fromJSON(needs.setup-pathways-parameters.outputs.worker_groups) }}
208227
with:
209228
device_type: tpu
210229
device_name: v6e-4
@@ -217,6 +236,8 @@ jobs:
217236
container_resource_option: "--privileged"
218237
is_scheduled_run: ${{ github.event_name == 'schedule' }}
219238
maxtext_sha: ${{ needs.build_and_upload_maxtext_package.outputs.maxtext_sha }}
239+
total_workers: ${{ needs.setup-pathways-parameters.outputs.total_workers }}
240+
worker_group: ${{ matrix.group }}
220241

221242
maxtext_tpu_pathways_integration_tests:
222243
needs: build_and_upload_maxtext_package

.github/workflows/run_pathways_tests.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ on:
5353
maxtext_sha:
5454
required: true
5555
type: string
56+
total_workers:
57+
required: false
58+
type: string
59+
default: '1'
60+
worker_group:
61+
required: false
62+
type: string
63+
default: '1'
64+
5665

5766
permissions:
5867
contents: read
@@ -95,6 +104,12 @@ jobs:
95104
run : gcloud storage cp gs://maxtext-test-assets/* tests/assets
96105
- name: Run Tests
97106
run: |
107+
if [ "${{ inputs.total_workers }}" -gt 1 ]; then
108+
.venv/bin/python3 -m pip install --quiet pytest-split
109+
SPLIT_ARGS="--splits ${{ inputs.total_workers }} --group ${{ inputs.worker_group }}"
110+
else
111+
SPLIT_ARGS=""
112+
fi
98113
if [ "${{ inputs.is_scheduled_run }}" = "true" ]; then
99114
FINAL_PYTEST_MARKER="${{ inputs.pytest_marker }}"
100115
else
@@ -105,7 +120,7 @@ jobs:
105120
export MAXTEXT_TEST_ASSETS_ROOT=$(pwd)/tests/assets
106121
export MAXTEXT_PKG_DIR=$(pwd)/src/maxtext
107122
# TODO(b/454659463): Enable test_default_hlo_match after volume mount is supported.
108-
.venv/bin/python3 -m pytest ${{ inputs.pytest_addopts }} -v -m "${FINAL_PYTEST_MARKER}" -k "not AotHloIdenticalTest and not CompileThenLoad" --durations=0
123+
.venv/bin/python3 -m pytest ${{ inputs.pytest_addopts }} -v -m "${FINAL_PYTEST_MARKER}" -k "not AotHloIdenticalTest and not CompileThenLoad" --durations=0 ${SPLIT_ARGS}
109124
env:
110125
PYTHONPATH: "${{ github.workspace }}/src"
111126
services:

.github/workflows/run_tests_against_package.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,13 @@ jobs:
176176
fi
177177
fi
178178
if [ "${INPUTS_TOTAL_WORKERS}" -gt 1 ]; then
179-
$PYTHON_EXE -m pip install --quiet pytest-split pytest-xdist
180-
SPLIT_ARGS="--splits ${INPUTS_TOTAL_WORKERS} --group ${INPUTS_WORKER_GROUP} -n auto"
179+
$PYTHON_EXE -m pip install --quiet pytest-split
180+
if [ "${INPUTS_DEVICE_TYPE}" = "tpu" ]; then
181+
SPLIT_ARGS="--splits ${INPUTS_TOTAL_WORKERS} --group ${INPUTS_WORKER_GROUP}"
182+
else
183+
$PYTHON_EXE -m pip install --quiet pytest-xdist
184+
SPLIT_ARGS="--splits ${INPUTS_TOTAL_WORKERS} --group ${INPUTS_WORKER_GROUP} -n auto"
185+
fi
181186
else
182187
SPLIT_ARGS=""
183188
fi

.github/workflows/run_tests_coordinator.yml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,48 @@ permissions:
6161
contents: read
6262

6363
jobs:
64+
setup-parameters:
65+
name: Setup Parameters
66+
runs-on: ubuntu-latest
67+
outputs:
68+
worker_groups: ${{ steps.set-params.outputs.worker_groups }}
69+
total_workers: ${{ steps.set-params.outputs.total_workers }}
70+
steps:
71+
- id: set-params
72+
name: Set Worker Parameters
73+
run: |
74+
# CPU worker constants
75+
CPU_UNIT_TOTAL_WORKERS=4
76+
CPU_UNIT_WORKER_GROUPS='[1, 2, 3, 4]'
77+
78+
# TPU worker constants
79+
TPU_UNIT_TOTAL_WORKERS=2
80+
TPU_UNIT_WORKER_GROUPS='[1, 2]'
81+
82+
# Default fallback constants
83+
DEFAULT_TOTAL_WORKERS=1
84+
DEFAULT_WORKER_GROUPS='[1]'
85+
86+
FLAVOR="${{ inputs.flavor }}"
87+
88+
if [[ "$FLAVOR" == "cpu-unit" || "$FLAVOR" == "cpu-post-training-unit" ]]; then
89+
echo "worker_groups=${CPU_UNIT_WORKER_GROUPS}" >> "$GITHUB_OUTPUT"
90+
echo "total_workers=${CPU_UNIT_TOTAL_WORKERS}" >> "$GITHUB_OUTPUT"
91+
elif [[ "$FLAVOR" == "tpu-unit" ]]; then
92+
echo "worker_groups=${TPU_UNIT_WORKER_GROUPS}" >> "$GITHUB_OUTPUT"
93+
echo "total_workers=${TPU_UNIT_TOTAL_WORKERS}" >> "$GITHUB_OUTPUT"
94+
else
95+
echo "worker_groups=${DEFAULT_WORKER_GROUPS}" >> "$GITHUB_OUTPUT"
96+
echo "total_workers=${DEFAULT_TOTAL_WORKERS}" >> "$GITHUB_OUTPUT"
97+
fi
98+
6499
execute-test-package:
100+
needs: setup-parameters
65101
name: ${{ inputs.flavor }}
66102
strategy:
67103
fail-fast: false
68104
matrix:
69-
worker_group: ${{ fromJSON(contains(inputs.flavor, 'cpu-unit') && '[1, 2, 3, 4]' || '[1]') }}
105+
worker_group: ${{ fromJSON(needs.setup-parameters.outputs.worker_groups) }}
70106

71107
uses: ./.github/workflows/run_tests_against_package.yml
72108
with:
@@ -158,6 +194,6 @@ jobs:
158194
is_scheduled_run: ${{ inputs.is_scheduled_run }}
159195
maxtext_installed: ${{ inputs.maxtext_installed }}
160196
worker_group: ${{ matrix.worker_group }}
161-
total_workers: ${{ contains(inputs.flavor, 'cpu-unit') && 4 || 1 }}
197+
total_workers: ${{ fromJSON(needs.setup-parameters.outputs.total_workers) }}
162198
maxtext_sha: ${{ inputs.maxtext_sha }}
163199
is_update_hlo: ${{ inputs.is_update_hlo }}

docs/guides/lora_model_bringup.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ To enable LoRA support for a new model, follow these two simple steps:
3030

3131
The target model architecture must already be implemented and supported as a base model in MaxText.
3232

33-
- The JAX/NNX model definition should be located under `src/maxtext/models/` (e.g., \[gemma3.py\](../../src/maxtext/models/gemma3.py)).
33+
- The JAX/NNX model definition should be located under `src/maxtext/models/` (e.g., [gemma3.py](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/models/gemma3.py)).
3434
- The model configurations must be registered and runnable for baseline pre-training or full fine-tuning.
3535

3636
### Step 1.2: Define Trainable LoRA Target Modules
3737

38-
Add a recommended target pattern for your model architecture prefix in \[src/maxtext/configs/post_train/lora_module_path.yml\](../../src/maxtext/configs/post_train/lora_module_path.yml):
38+
Add a recommended target pattern for your model architecture prefix in [src/maxtext/configs/post_train/lora_module_path.yml](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/configs/post_train/lora_module_path.yml):
3939

4040
```yaml
4141
your_model_prefix: "decoder/layers/.*(self_attention/(query|key|value|out)|mlp/(wi_0|wi_1|wo))"
@@ -69,7 +69,7 @@ If you want to perform decoding or run high-performance serving on your adapted
6969
To add weight mapping for vLLM decode:
7070

7171
1. **Create a Weight Mapping Config**:
72-
Create a new file in \[src/maxtext/integration/tunix/weight_mapping/\](../../src/maxtext/integration/tunix/weight_mapping/) (e.g., `your_model.py`) defining a mapping dataclass. You can refer to \[gemma3.py\](../../src/maxtext/integration/tunix/weight_mapping/gemma3.py) or \[llama3.py\](../../src/maxtext/integration/tunix/weight_mapping/llama3.py) as templates.
72+
Create a new file in [src/maxtext/integration/tunix/weight_mapping/](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/integration/tunix/weight_mapping/) (e.g., `your_model.py`) defining a mapping dataclass. You can refer to [llama3.py](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/integration/tunix/weight_mapping/llama3.py) as a template.
7373

7474
Your class should specify:
7575

@@ -78,7 +78,7 @@ To add weight mapping for vLLM decode:
7878
- `lora_to_hf_mappings()`: Custom mapping for LoRA weights if they require different handling.
7979

8080
2. **Register the Mapping**:
81-
Register your new class in \[src/maxtext/integration/tunix/weight_mapping/__init__.py\](../../src/maxtext/integration/tunix/weight_mapping/__init__.py) inside the `StandaloneVllmWeightMapping` class:
81+
Register your new class in [src/maxtext/integration/tunix/weight_mapping/__init__.py](https://github.com/AI-Hypercomputer/maxtext/blob/main/src/maxtext/integration/tunix/weight_mapping/__init__.py) inside the `StandaloneVllmWeightMapping` class:
8282

8383
```python
8484
# Inside StandaloneVllmWeightMapping

docs/reference/core_concepts/moe_configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ Dropping:
9999

100100
`mlp_bias`: If enabled, add learnable bias terms for MLP matmul. Originally implemented to support the GPT-OSS model architecture.
101101

102+
`prefuse_moe_weights`: If enabled alongside `sparse_matmul=True`, fuses the two FFN1 grouped GEMMs (wi\_0 and wi\_1) into a single grouped GEMM call. Expert weights are stored in a concatenated `(num_experts, embed_dim, 2 * mlp_dim)` shape, so input activations are loaded from HBM once per forward pass instead of twice. Backend-agnostic (works with Megablox, JAX Ragged Dot, and Tokamax). When used with `attention=vllm_rpa`, the fused weight tensor is passed directly to the vLLM-TPU serving kernel without splitting.
103+
102104
`use_batch_split_schedule` (experimental): If enabled, split batch into micro-batches to hide communications that yields performance benefits.
103105

104106
## 2. Sharding

src/maxtext/checkpoint_conversion/to_maxtext.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
from maxtext.common.common_types import MODEL_MODE_TRAIN
6868
from maxtext.checkpoint_conversion.utils.hf_model_configs import HF_MODEL_CONFIGS
6969
from maxtext.checkpoint_conversion.utils.param_mapping import HOOK_FNS, PARAM_MAPPING
70-
from maxtext.checkpoint_conversion.utils.utils import MemoryMonitorTqdm, apply_hook_fns, load_hf_dict_from_transformers, load_hf_dict_from_safetensors, param_key_parts_from_path, print_peak_memory, print_ram_usage, save_weights_to_checkpoint, validate_and_filter_param_map_keys
70+
from maxtext.checkpoint_conversion.utils.tensor_handling import apply_hook_fns
71+
from maxtext.checkpoint_conversion.utils.utils import MemoryMonitorTqdm, load_hf_dict_from_transformers, load_hf_dict_from_safetensors, param_key_parts_from_path, print_peak_memory, print_ram_usage, save_weights_to_checkpoint, validate_and_filter_param_map_keys
7172
from maxtext.inference.inference_utils import str2bool
7273
from maxtext.layers import quantizations
7374
from maxtext.models import models
@@ -319,22 +320,21 @@ def get_maxtext_model_info(config):
319320
# Get abstract model structure (name, shape) without materializing the weights to save memory
320321
abstract_params_tree = maxtext_utils.get_abstract_param(maxtext_model_flax, config)["params"]
321322

322-
abstract_params_flat, _ = jax.tree_util.tree_flatten_with_path(abstract_params_tree)
323-
# Standardize abstract tree for later unflattening
324-
abstract_params_tree = jax.tree.map(
325-
lambda _: 0,
323+
abstract_params_flat, abstract_params_treedef = jax.tree_util.tree_flatten_with_path(
326324
abstract_params_tree,
327325
is_leaf=lambda x: isinstance(x, nn.LogicallyPartitioned),
328326
)
329-
abstract_params_treedef = jax.tree_util.tree_structure(abstract_params_tree)
330327

331328
max_logging.log("MaxText abstract model and state initialized.")
332329

333330
# preprocess state
334331
maxtext_abstract_dict = {}
335332
for mt_target_idx, (path_tuple, abstract_leaf_value) in enumerate(abstract_params_flat):
336333
mt_param_key = "params-" + "-".join(param_key_parts_from_path(path_tuple))
337-
mt_target_shape = abstract_leaf_value.shape
334+
if isinstance(abstract_leaf_value, nn.LogicallyPartitioned):
335+
mt_target_shape = abstract_leaf_value.value.shape
336+
else:
337+
mt_target_shape = abstract_leaf_value.shape
338338
maxtext_abstract_dict[mt_param_key] = (mt_target_idx, mt_target_shape)
339339

340340
return maxtext_abstract_dict, abstract_params_treedef

src/maxtext/checkpoint_conversion/utils/hf_model_configs.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,62 @@ def __init__(self, **kwargs):
16421642
}
16431643
qwen3_vl_4b_config = PTConfig(**qwen3_vl_4b_dict)
16441644

1645+
qwen3_vl_2b_dict = {
1646+
"architectures": ["Qwen3VLForConditionalGeneration"],
1647+
"image_token_id": 151655,
1648+
"model_type": "qwen3_vl",
1649+
"text_config": {
1650+
"attention_bias": False,
1651+
"attention_dropout": 0.0,
1652+
"bos_token_id": 151643,
1653+
"dtype": "bfloat16",
1654+
"eos_token_id": 151645,
1655+
"head_dim": 128,
1656+
"hidden_act": "silu",
1657+
"hidden_size": 2048,
1658+
"initializer_range": 0.02,
1659+
"intermediate_size": 6144,
1660+
"max_position_embeddings": 262144,
1661+
"model_type": "qwen3_vl_text",
1662+
"num_attention_heads": 16,
1663+
"num_hidden_layers": 28,
1664+
"num_key_value_heads": 8,
1665+
"pad_token_id": None,
1666+
"rms_norm_eps": 1e-06,
1667+
"rope_parameters": {
1668+
"mrope_interleaved": True,
1669+
"mrope_section": [24, 20, 20],
1670+
"rope_theta": 5000000,
1671+
"rope_type": "default",
1672+
},
1673+
"tie_word_embeddings": True,
1674+
"use_cache": True,
1675+
"vocab_size": 151936,
1676+
},
1677+
"tie_word_embeddings": True,
1678+
"transformers_version": "4.57.0.dev0",
1679+
"video_token_id": 151656,
1680+
"vision_config": {
1681+
"deepstack_visual_indexes": [5, 11, 17],
1682+
"depth": 24,
1683+
"hidden_act": "gelu_pytorch_tanh",
1684+
"hidden_size": 1024,
1685+
"in_channels": 3,
1686+
"initializer_range": 0.02,
1687+
"intermediate_size": 4096,
1688+
"model_type": "qwen3_vl_vision",
1689+
"num_heads": 16,
1690+
"num_position_embeddings": 2304,
1691+
"out_hidden_size": 2048,
1692+
"patch_size": 16,
1693+
"spatial_merge_size": 2,
1694+
"temporal_patch_size": 2,
1695+
},
1696+
"vision_end_token_id": 151653,
1697+
"vision_start_token_id": 151652,
1698+
}
1699+
qwen3_vl_2b_config = PTConfig(**qwen3_vl_2b_dict)
1700+
16451701

16461702
# {maxtext model name: hf model config}
16471703
HF_MODEL_CONFIGS = {
@@ -1669,6 +1725,7 @@ def __init__(self, **kwargs):
16691725
"qwen3-14b": qwen3_14b_config,
16701726
"qwen3-14b-base": qwen3_14b_config,
16711727
"qwen3-32b": qwen3_32b_config,
1728+
"qwen3-vl-2b": qwen3_vl_2b_config,
16721729
"qwen3-vl-4b": qwen3_vl_4b_config,
16731730
"llama3.1-8b": llama31_8b_config,
16741731
"llama3.1-8b-Instruct": llama31_8b_config,

src/maxtext/checkpoint_conversion/utils/hf_shape.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,7 @@ def QWEN3_VL_HF_WEIGHTS_TO_SHAPE(config):
11821182
"qwen3-8b": QWEN_HF_WEIGHTS_TO_SHAPE,
11831183
"qwen3-14b": QWEN_HF_WEIGHTS_TO_SHAPE,
11841184
"qwen3-32b": QWEN_HF_WEIGHTS_TO_SHAPE,
1185+
"qwen3-vl-2b": QWEN3_VL_HF_WEIGHTS_TO_SHAPE,
11851186
"qwen3-vl-4b": QWEN3_VL_HF_WEIGHTS_TO_SHAPE,
11861187
"llama3.1-8b": LLAMA31_HF_WEIGHTS_TO_SHAPE,
11871188
"llama3.1-8b-Instruct": LLAMA31_HF_WEIGHTS_TO_SHAPE,

0 commit comments

Comments
 (0)