Skip to content

[MLPerf] Add DLRM-DCNv2 #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open

Conversation

abheesht17
Copy link
Collaborator

@abheesht17 abheesht17 commented Aug 18, 2025

TODOs:

  • Need to make it work for multi-host: Multi-host training does not work for distributed embeddings #143.
  • Currently uses dummy data, need to shift it to using the actual dataset. Already added code for loading actual data, but the path we are reading already has "batched" data. Can go ahead with this, or can load "unbatched" data and batch that up.
  • Eval dataset
  • Check if random seed is being correctly passed. We need to make sure that the initialiser returns different values for different layers (since we are passing SeedGenerator, I think we are good, but good to verify manually).
  • Instead of separate files for configs, maybe have separate functions for configs.
  • Is this a worry?
 08:44:12.046114: W jax_tpu_embedding/sparsecore/lib/core/input_preprocessing_util.cc:251] No Coo Buffer Size provided for table cat_14_table_cat_15_table_cat_23_table_cat_24_table_cat_25_table_cat_33_table_cat_34_table_cat_35_table_cat_36_table, the default value (6144) may be too large and can cause OOM. Utilize the stats returned from the sparse dense matmul preprocessing API.
  • Set up metric logging and checkpointing.

@abheesht17 abheesht17 requested a review from hertschuh August 18, 2025 08:48
Copy link

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

Choose a reason for hiding this comment

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

Summary of Changes

Hello @abheesht17, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the DLRM-DCNv2 model as an MLPerf example, designed for efficient training on TPUs. It provides the model architecture, configuration files for dataset, model, and training hyperparameters, a dummy data loader, and a comprehensive shell script to set up the TPU environment and execute the training process. The current implementation uses dummy data and has known areas for future improvement, such as multi-host support and actual dataset integration.

Highlights

  • New Model Implementation: Adds the DLRM-DCNv2 model, a deep learning architecture combining deep neural networks with a cross-network for learning explicit feature interactions, commonly used in recommendation systems.
  • TPU Integration: Leverages Keras's distributed training capabilities with JAX backend and keras_rs.layers.DistributedEmbedding for efficient large-scale embedding table handling on TPUs, including SparseCore.
  • Modular Configuration: Introduces a structured configuration system using keras.utils.Config for defining dataset features, model parameters (embedding dimensions, MLP layers, DCN layers), and training hyperparameters.
  • Automated Setup Script: Provides a run.sh script to automate the entire setup process on Google Cloud TPU VMs, from VM creation and environment setup to dependency installation and model execution.
  • Dummy Data Support: Includes a dataloader.py to generate dummy data, enabling initial testing and development of the DLRM-DCNv2 model before integration with real datasets.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

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

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 a DLRM-DCNv2 model implementation for MLPerf benchmarks, including configurations, a dummy dataloader, the model definition, and a run script. The overall structure is good, but there are several critical and high-severity issues that need to be addressed. Specifically, there are bugs related to weight initialization due to seed reuse in loops, which will lead to layers having identical weights. There's also a potential runtime error in the model's forward pass due to improper handling of an empty list during tensor concatenation. Additionally, the main training script has a hardcoded number of epochs, ignoring the value from the configuration. I've also included some medium-severity suggestions to improve code maintainability and script robustness. Please review the detailed comments.

vocabulary_size=vocabulary_size,
embedding_dim=embedding_dim,
# TODO(abheesht): Verify.
initializer=keras.initializers.VarianceScaling(
Copy link
Collaborator

Choose a reason for hiding this comment

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

The default is keras.initializers.VarianceScaling(mode="fan_out"), which has a scale of 1 and a uniform distribution.

Why did you need to change it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

from .dataloader import DataLoader
from .model import DLRMDCNV2

SEED = 1337
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like you carefully passed the SEED everywhere, but it's hard to say if you missed one.

I would also do keras.config.set_random_seed(SEED) just to make sure things are consistent across hosts.

Copy link
Collaborator Author

@abheesht17 abheesht17 Aug 20, 2025

Choose a reason for hiding this comment

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

I would also do keras.config.set_random_seed(SEED) just to make sure things are consistent across hosts.

Won't this return the same output given the same input shape (for initialisers)? Does it take care to use a SeedGenerator() so that the seed is incremented for every call?

),
combiner="sum",
placement="sparsecore",
# TODO: These two args are not getting passed down to
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could try these XLA flags:

  • xla_sparse_core_max_ids_per_partition_per_sample
  • xla_sparse_core_max_unique_ids_per_partition_per_sample

table=table_config,
# TODO: Verify whether it should be `(bsz, 1)` or
# `(bsz, multi_hot_size)`.
input_shape=(per_host_batch_size, multi_hot_size),
Copy link
Collaborator

Choose a reason for hiding this comment

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

multi_hot as an input to embedding tables is not supported, it should be turned into a ragged or padded sequence of indices before being fed to the DistributedEmbedding.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmmm, I don't see happening here though: https://github.com/AI-Hypercomputer/RecML/blob/1821350b346b66479baaa0ab624aa67929305dea/examples/dlrm/dlrm_main.py#L245-L249. They use (bsz, 1). Not sure why, will check with them

Copy link
Collaborator Author

@abheesht17 abheesht17 Aug 20, 2025

Choose a reason for hiding this comment

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

multi_hot as an input to embedding tables is not supported, it should be turned into a ragged or padded sequence of indices before being fed to the DistributedEmbedding.

Oh, I think our understanding of multi-hot is different. I think what you mean by multi-hot is [[1, 0, 1, 0, 0], [0, 0, 1, 1, 1]]. I am passing indices here though. I should rename it to something else, it's confusing to keep multi_hot

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

np.random.randint(
                low=0,
                high=vocabulary_size,
                size=(self.batch_size, multi_hot_size),
                dtype=np.int64,
            )

@abheesht17 abheesht17 requested a review from hertschuh August 20, 2025 13:51
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.

2 participants