Skip to content
Draft
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
309 changes: 54 additions & 255 deletions src/maxtext/experimental/rl/grpo_trainer.py

Large diffs are not rendered by default.

588 changes: 142 additions & 446 deletions src/maxtext/inference/maxengine/maxengine.py

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions src/maxtext/inference/vllm_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ def decode_with_vllm(config: Config) -> None:
"debug_sharding": config.debug_sharding,
"prefuse_moe_weights": config.prefuse_moe_weights,
"scan_layers": config.scan_layers,
"enable_nnx": config.enable_nnx,
"pure_nnx_decoder": config.pure_nnx_decoder,
},
"sharding": {
"sharding_strategy": {
Expand Down Expand Up @@ -248,8 +246,6 @@ def decode_with_tunix(
"debug_sharding": config.debug_sharding,
"prefuse_moe_weights": config.prefuse_moe_weights,
"scan_layers": config.scan_layers,
"enable_nnx": config.enable_nnx,
"pure_nnx_decoder": config.pure_nnx_decoder,
}
}

Expand Down
48 changes: 22 additions & 26 deletions src/maxtext/layers/quantizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,32 +877,28 @@ def maybe_quantize_model(model, config):
if config.quantization and config.use_qwix_quantization and not config.use_batch_split_schedule:
quantization_provider = get_qt_provider(config)
if quantization_provider:
if config.pure_nnx:
input_shape = (config.micro_batch_size_to_train_on, config.max_target_length)
dummy_tokens = jnp.ones(input_shape, dtype=jnp.int32)
dummy_positions = jnp.ones(input_shape, dtype=jnp.int32)
dummy_segment_ids = jnp.ones(input_shape, dtype=jnp.int32)
# The MTP block reads the decoder targets, so the qwix forward pass needs them.
# The Linen path supplies them from the is_initializing() guard in Transformer.
dummy_targets = {}
if config.mtp_num_layers > 0:
dummy_targets["decoder_target_tokens"] = jnp.ones(input_shape, dtype=jnp.int32)
dummy_targets["decoder_target_mask"] = jnp.ones(input_shape, dtype=jnp.int32)
model = qwix.quantize_model(
model,
quantization_provider,
dummy_tokens,
dummy_positions,
dummy_segment_ids,
enable_dropout=False,
**dummy_targets,
)
# Qwix quantization runs a forward pass during tracing, which sows transient nnx.Intermediate variables
# (e.g. max_logits from QK-Clip, MTP losses) into the model. Popping them here prevents structural mismatches
# between the initial setup GraphDef/state_mesh_shardings and the stripped states during train steps.
nnx.pop(model, nnx.Intermediate)
else:
model = qwix.quantize_model(model, quantization_provider)
input_shape = (config.micro_batch_size_to_train_on, config.max_target_length)
dummy_tokens = jnp.ones(input_shape, dtype=jnp.int32)
dummy_positions = jnp.ones(input_shape, dtype=jnp.int32)
dummy_segment_ids = jnp.ones(input_shape, dtype=jnp.int32)
# The MTP block reads the decoder targets, so the qwix forward pass needs them.
dummy_targets = {}
if config.mtp_num_layers > 0:
dummy_targets["decoder_target_tokens"] = jnp.ones(input_shape, dtype=jnp.int32)
dummy_targets["decoder_target_mask"] = jnp.ones(input_shape, dtype=jnp.int32)
model = qwix.quantize_model(
model,
quantization_provider,
dummy_tokens,
dummy_positions,
dummy_segment_ids,
enable_dropout=False,
**dummy_targets,
)
# Qwix quantization runs a forward pass during tracing, which sows transient nnx.Intermediate variables
# (e.g. max_logits from QK-Clip, MTP losses) into the model. Popping them here prevents structural mismatches
# between the initial setup GraphDef/state_mesh_shardings and the stripped states during train steps.
nnx.pop(model, nnx.Intermediate)
for _, val in nnx.graph.iter_graph(model):
if hasattr(val, "__dict__") and "qwix_rngs" in val.__dict__:
del val.qwix_rngs
Expand Down
Loading
Loading