-
Notifications
You must be signed in to change notification settings - Fork 14
[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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
-
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. ↩
There was a problem hiding this 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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
examples/ml_perf/main.py
Outdated
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), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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,
)
TODOs:
SeedGenerator
, I think we are good, but good to verify manually).Instead of separate files for configs, maybe have separate functions for configs.