Skip to content

Fix DeepSeek4HyperHead compilation error - #4778

Closed
olufiyin19 wants to merge 2 commits into
fix-validation-pipeline-deepseek4-284b-dag_verify_checkpoint_shape-manual__47c2f1c4-checkpoint_shape_validationfrom
fix-validation-pipeline-deepseek4-284b-dag_verify_checkpoint_shape-manual__2026-08-07T16-45-22-682758-00-00-checkpoint_
Closed

Fix DeepSeek4HyperHead compilation error#4778
olufiyin19 wants to merge 2 commits into
fix-validation-pipeline-deepseek4-284b-dag_verify_checkpoint_shape-manual__47c2f1c4-checkpoint_shape_validationfrom
fix-validation-pipeline-deepseek4-284b-dag_verify_checkpoint_shape-manual__2026-08-07T16-45-22-682758-00-00-checkpoint_

Conversation

@olufiyin19

Copy link
Copy Markdown
Collaborator

Fix DeepSeek4HyperHead compilation error

@google-cla

google-cla Bot commented Aug 7, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the DeepSeek4HyperHead module to support DeepSeek V4 hyper heads, which reduces the expansion rate dimension and applies a series of dense layers. This head is integrated into the decoder initialization and call paths when mhc_expansion_rate > 1 and the decoder block is DEEPSEEK4. Feedback on these changes highlights two main issues: first, accessing config.mhc_expansion_rate directly can raise an AttributeError on configurations where it is not defined, so using getattr is recommended; second, the DenseGeneral layers in DeepSeek4HyperHead should be configured with proper sharding, precision, and offloading parameters to prevent potential out-of-memory (OOM) errors and ensure consistency.

self.is_gemma4 = self.config.decoder_block == DecoderBlockType.GEMMA4
self.is_gemma4_small = self.config.decoder_block == DecoderBlockType.GEMMA4_SMALL

if config.mhc_expansion_rate > 1 and config.decoder_block == DecoderBlockType.DEEPSEEK4:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

Accessing config.mhc_expansion_rate directly will raise an AttributeError for any model configuration that does not define mhc_expansion_rate (such as standard LLaMA or Gemma models). Using getattr(config, "mhc_expansion_rate", 1) prevents this crash and safely defaults to 1 when the attribute is missing.

Suggested change
if config.mhc_expansion_rate > 1 and config.decoder_block == DecoderBlockType.DEEPSEEK4:
if getattr(config, "mhc_expansion_rate", 1) > 1 and config.decoder_block == DecoderBlockType.DEEPSEEK4:

Comment thread src/maxtext/layers/mhc.py
Comment on lines +336 to +342
linears.DenseGeneral(
in_features_shape=self.dim,
out_features_shape=self.dim,
dtype=self.dtype,
weight_dtype=self.weight_dtype,
rngs=self.rngs,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The DenseGeneral layers inside DeepSeek4HyperHead are initialized without specifying logical kernel_axes, shard_mode, matmul_precision, and parameter_memory_host_offload. Without these, the weight matrices will not be sharded (replicated instead), which can lead to high memory usage and potential Out-Of-Memory (OOM) errors during large-scale training. Additionally, the layers will not respect the user's configuration for sharding, precision, and offloading. Specifying these parameters ensures proper FSDP sharding and consistency with the rest of the model.

            linears.DenseGeneral(
                in_features_shape=self.dim,
                out_features_shape=self.dim,
                dtype=self.dtype,
                weight_dtype=self.weight_dtype,
                kernel_axes=("embed", None),
                shard_mode=config.shard_mode,
                matmul_precision=config.matmul_precision,
                parameter_memory_host_offload=config.parameter_memory_host_offload,
                rngs=self.rngs,
            )

@olufiyin19 olufiyin19 closed this Aug 8, 2026
@olufiyin19
olufiyin19 deleted the fix-validation-pipeline-deepseek4-284b-dag_verify_checkpoint_shape-manual__2026-08-07T16-45-22-682758-00-00-checkpoint_ branch August 8, 2026 00:30
@codecov

codecov Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 23.80952% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/maxtext/layers/mhc.py 31.25% 11 Missing ⚠️
src/maxtext/layers/nnx_decoders.py 0.00% 4 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant