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
2 changes: 1 addition & 1 deletion src/maxtext/layers/nnx_decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def __init__(
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:
if getattr(config, "mhc_expansion_rate", 1) > 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.

medium

If mhc_expansion_rate is explicitly set to None in the configuration, getattr(config, "mhc_expansion_rate", 1) will return None because the attribute exists but its value is None. Comparing None > 1 will then raise a TypeError. To prevent this, we should ensure a fallback value of 1 is used if the attribute is either missing or None.

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

self.hc_head = mhc.DeepSeek4HyperHead(
config=config,
mesh=self.mesh,
Expand Down
6 changes: 6 additions & 0 deletions tests/utils/forward_pass_logit_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@ def main(config, test_args): # pylint: disable=W0621
try:
max_logging.log(f"Loading tokenizer from {path}.")
tokenizer = AutoTokenizer.from_pretrained(path, token=hf_token, trust_remote_code=test_args.trust_remote_code)
# Mistral and Llama tokenizers ship no pad token, and the calls below pass padding=True, which
# transformers refuses without one ("Asking to pad but the tokenizer does not have a padding
# token"). Prompts are tokenized one at a time here, so nothing is ever actually padded and
# borrowing eos changes no result -- it only satisfies the check that rejects the call.
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
Comment on lines +386 to +387

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

If tokenizer.eos_token is also None, setting tokenizer.pad_token = tokenizer.eos_token will keep the pad token as None, which will still cause the padding error. Adding a fallback to tokenizer.bos_token improves robustness for tokenizers that might not have an EOS token defined but have a BOS token.

Suggested change
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token or tokenizer.bos_token

break
except Exception as e: # pylint: disable=broad-except,broad-exception-caught
last_exception = e
Expand Down
Loading