Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion docs/guides/optimization/benchmark_and_performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Different quantization recipes are available, including` "int8", "fp8", "fp8_ful

For v6e and earlier generation TPUs, use the "int8" recipe. For v7x and later generation TPUs, use "fp8_full". GPUs should use “fp8_gpu” for NVIDIA and "nanoo_fp8" for AMD.

See [](quantization-doc).
See [Quantization guide](../../reference/core_concepts/quantization.md).

### Choose sharding strategy

Expand Down
2 changes: 2 additions & 0 deletions docs/reference/core_concepts/moe_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ Dropping:

`use_tokamax_gmm`: If enabled, use Tokamax library's Ragged Dot for matmul. Recommended for dropless configurations.

`use_gmm_v2`: If enabled, use the Tokamax GMM v2 kernel for grouped matrix multiplication. Requires `use_tokamax_gmm` to be True.

`megablox`: If enabled, use Megablox for sparse matrix operations. Effective only when `use_tokamax_gmm` is False.

`capacity_factor`: A scalar multiplier for expert capacity. Effective only when `sparse_matmul` is False.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MaxText is an open-source, high-performance LLM framework written in Python/JAX.

- **Supported Precisions**: FP32, BF16, INT8, and FP8.
- **Ahead-of-Time Compilation (AOT)**: For faster model development/prototyping and earlier OOM detection.
- **Quantization**: Via **Qwix** (recommended) and AQT (deprecated). See the [Quantization guide](quantization-doc).
- **Quantization**: Via **Qwix** (recommended) and AQT (deprecated). See the [Quantization guide](../core_concepts/quantization.md).
- **Diagnostics**: Simple logging via `max_logging`, profiling in **XProf**, and visualization in **TensorBoard**.
- **Multi-Token Prediction (MTP)**: Enables token efficient training with multi-token prediction.
- **Elastic Training**: Fault-tolerant and dynamic scale-up/scale-down on Cloud TPUs with Pathways.
Expand Down
3 changes: 3 additions & 0 deletions src/maxtext/common/checkpointing.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,9 @@ def _should_save_checkpoint_at_step(checkpoint_manager, step, config, force):
"""Returns whether MaxText should build and dispatch checkpoint args."""
if force:
return True
if step == 0 and not config.save_checkpoint_on_start:
# if step = 0, `step % config.checkpoint_period == 0` is always true, force skip
return False
if config.enable_continuous_checkpointing:
base_checkpoint_due = bool(checkpoint_manager.should_save(step))
else:
Expand Down
13 changes: 7 additions & 6 deletions src/maxtext/configs/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ load_full_state_path: ""
# async_checkpointing is true, else a synchronous one is used. If you have
# problems with the checkpointer we recommend trying the synchronous one.
enable_checkpointing: true
save_checkpoint_on_start: true
save_checkpoint_on_completion: true
async_checkpointing: true
checkpoint_period: 10_000
Expand Down Expand Up @@ -141,7 +142,7 @@ kv_quant_dtype: "int8"
checkpoint_is_quantized: false # set to true if reading from a saved aqt quantized checkpoint
# saves params quantized on fly at following path
save_quantized_params_path: ""
#used to configure the mode in which model is called
# used to configure the mode in which model is called
# when left as is, corresponds to training
# accepted values are "inference"
model_call_mode: ""
Expand Down Expand Up @@ -267,6 +268,11 @@ wo_tile_drhs_mlp_dim: 1024

merge_gating_gmm: false

# Use tokamax library for gmm kernel implementation
use_tokamax_gmm: false
# Whether to use Tokamax GMM v2 for MoE kernel. Requires use_tokamax_gmm=true.
use_gmm_v2: false

norm_topk_prob: false # boolean to enable the top-k probability normalization. qwen3-specific normalization of router weights.

# when moe weight matrices are sharded on both fsdp and fsdp-transpose axes, use two separate all-gather calls
Expand Down Expand Up @@ -1268,11 +1274,6 @@ use_qk_norm_in_gdn: true
# The ratio of dimension to apply ROPE on
partial_rotary_factor: 1.0

# Use tokamax library for gmm kernel implementation
use_tokamax_gmm: false
# Whether to use GMM v2 for MoE.
# Requires use_tokamax_gmm: true. Currently incompatible with quantization.
use_gmm_v2: false
use_tokamax_splash: false
# Setting this flag will use a non-pallas implementation.
use_jax_splash: false
Expand Down
1 change: 0 additions & 1 deletion src/maxtext/configs/pyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from maxtext.utils import max_logging

logger = logging.getLogger(__name__)
logger.setLevel(os.environ.get("LOGLEVEL", "INFO"))

_BASE_CONFIG_ATTR = "base_config"
_MAX_PREFIX = "M_"
Expand Down
45 changes: 26 additions & 19 deletions src/maxtext/configs/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ class Checkpointing(BaseModel):
source_checkpoint_layout: Literal["orbax", "safetensors", "safetensors_dynamic"] = Field(
"orbax", description="The layout of the source checkpoint to load."
)
save_checkpoint_on_start: bool = Field(True, description="If True, saves an initial checkpoint upon training start.")
save_checkpoint_on_completion: bool = Field(
True, description="If True, saves a final checkpoint upon training completion."
)
Expand Down Expand Up @@ -450,7 +451,7 @@ class Quantization(BaseModel):
use_qwix_quantization: bool = Field(False, description="Whether to use qwix for quantization.")
use_manual_quantization: bool = Field(
False,
description="Whether to use manual quantization for batch split. Only used if use_batch_split_schedule is True.",
description="Whether to use manual quantization for batch split. Only used if `use_batch_split_schedule=True`.",
)
weight_quantization_calibration_method: str = Field(
"absmax",
Expand Down Expand Up @@ -626,20 +627,6 @@ class Attention(BaseModel):
use_post_attn_norm: bool = Field(False, description="Apply LayerNorm after the attention block.")
use_post_ffw_norm: bool = Field(False, description="Apply LayerNorm after the feed-forward block.")
use_ragged_attention: bool = Field(False, description="Whether to use ragged attention kernels.")
use_tokamax_gmm: bool = Field(
False,
description="Whether to use the Tokamax library for GMM kernel implementation.",
)
use_gmm_v2: bool = Field(
Comment thread
shuningjin marked this conversation as resolved.
False,
description=(
"Whether to use GMM v2 (with bf16 activations and weights) for MoE."
" Requires use_tokamax_gmm: true. Currently incompatible with quantization."
),
)
num_moe_emb_chunks: int = Field(
0, description="Number of chunks for overlapping token all-gather and GMM computation along embedding dimension."
)
ragged_block_size: int = Field(256, description="Block size for ragged attention.")
enable_padding_causal_mask: bool = Field(True, description="Temporary flag for Transformer Engine padding.")
use_tokamax_splash: bool = Field(False, description="Whether to use tokamax splash attention.")
Expand Down Expand Up @@ -998,6 +985,21 @@ class MoEKernels(BaseModel):

merge_gating_gmm: bool = Field(False, description="whether to merge the two gating gmm kernels into one.")

num_moe_emb_chunks: int = Field(
0, description="Number of chunks for overlapping token all-gather and GMM computation along embedding dimension."
)

# tokamax gmm
use_tokamax_gmm: bool = Field(
False,
description="Whether to use the Tokamax library for GMM kernel implementation.",
)

use_gmm_v2: bool = Field(
False,
description="Whether to use Tokamax GMM v2 for MoE kernel.",
)


class DeepSeekMoE(BaseModel):
"""Configuration specific to DeepSeek-style MoE layers."""
Expand Down Expand Up @@ -3772,10 +3774,15 @@ def calculate_global_batch_sizes(per_device_batch_size, expansion_factor, num_de
if self.share_kv_projections and self.attention_type == "mla":
raise ValueError("`share_kv_projections` is not compatible with `attention_type='mla'`.")

if self.use_gmm_v2 and (self.quantization or self.use_qwix_quantization):
raise ValueError("Quantization with GMM v2 is not supported yet.")
if self.use_gmm_v2 and not self.use_tokamax_gmm:
raise ValueError("GMM v2 requires `use_tokamax_gmm=true`.")
if self.use_manual_quantization and not self.use_batch_split_schedule:
raise ValueError("manual quantization is only used when `use_batch_split_schedule=True`.")

# Validation for GMM v2
if self.use_gmm_v2:
if not self.use_tokamax_gmm:
raise ValueError("GMM v2 requires `use_tokamax_gmm=True`.")
if self.use_batch_split_schedule:
raise ValueError("GMM v2 is not supported with a batch split schedule.")

for val in self.compress_ratios:
if val != 0 and val < 4:
Expand Down
Loading
Loading