Comments (2)
Hi Frankwwu
Thanks for the post. There might be different things in play. Following are some possible explanation & solutions:
- TF-DF works (currently) by loading the entire dataset in memory. The memory usage is ~4 bytes per numerical and categorical values. For example, a dataset with 1M examples and 100 features will use 400MB. Colabs has a default RAM limit of 12GB (for everything; not just the dataset).
It might be interesting to increase it for large datasets.
- Categorical-set features will consume more than 4 bytes. At the start of the training, the logs will show what is the type of each feature.
Make sure the type of each feature is as expected.
- To speed-up training, numerical features are pre-sorted. This index consumes a significant amount of memory (~2x the dataset memory usage).
This index can be disabled as follow:
# Access to advanced hyper-parameters.
# See .proto sections in https://github.com/google/yggdrasil-decision-forests/blob/main/documentation/learners.md for mode details.
from yggdrasil_decision_forests.learner.random_forest import random_forest_pb2
from yggdrasil_decision_forests.learner.decision_tree import decision_tree_pb2
# Disable the pre-sorting of numerical features.
yggdrasil_training_config = tfdf.keras.core.YggdrasilTrainingConfig()
advanced_rf_config = yggdrasil_training_config.Extensions[random_forest_pb2.random_forest_config]
advanced_rf_config.decision_tree.internal.sorting_strategy = decision_tree_pb2.DecisionTreeTrainingConfig.Internal.SortingStrategy.IN_NODE
advanced_arguments = tfdf.keras.AdvancedArguments(yggdrasil_training_config=yggdrasil_training_config)
model = tfdf.keras.GradientBoostedTreesModel(num_trees=300, advanced_arguments=advanced_arguments)
with sys_pipes():
model.fit(train_ds)
Note: I am setting a TODO to make it easier to disable the index construction.
- The size of the model is generally not an issue. However, an incorrectly configured training can lead to a large model. For example, training a classification model on a regression problem might lead to large models as each possible numerical value will be treated as a separate class.
Make sure the task
argument of the model constructor is set appropriately.
- We are working on open sourcing solutions for large datasets (e.g. >1B examples).
In the meantime, a possible workaround is to train an ensemble of models where each model is trained on a small subset of the dataset.
from decision-forests.
TF-DF 0.1.6 introduces the parameter sorting_strategy
to disable easily the creation of the index (and reduce the memory consumption significantly).
The following code is equivalent to the code snippet given above with AdvancedArguments
.
model = tfdf.keras.GradientBoostedTreesModel(num_trees=300, sorting_strategy="IN_NODE")
from decision-forests.
Related Issues (20)
- Models trained on pure 1's predict 0 HOT 3
- max_vocab_count won't work for CATEGORICAL integerized in tfdf.keras.GradientBoostedTreesModel HOT 5
- Save and load model with tunning in automatic_tuning_colab.ipynb HOT 4
- Symbol not found, but versions are compatible according to the website HOT 4
- Loading a model returns either an untrained model or broken model HOT 1
- Using call_get_leaves inside @tf.function call in ensemble model inherits from tensorflow.keras.Model HOT 10
- no wheels for apple silicon (macos-arm64) HOT 2
- ANE support through coremltools HOT 4
- Can't use both `sample_weight` and `class_weight` at the same time HOT 1
- Is there a method like ydf.load_model() to load model get a instance of tfdf.keras.RandomForestModel? HOT 2
- decision forests tutorial tf_df_in_tf_js code wasn't working for me
- gpu support for layer use HOT 1
- DistributedGradientBoostedTreesModel does not support Ranking task HOT 1
- TF-DF Compatibility with Keras 3? HOT 6
- make_inspector() throws object of type 'NoneType' has no len() when I retrieve TF DF RF model layer in the hybrid model HOT 3
- tfdf 1.9.0 only compatible with tf 2.16.1 which ships Keras 3 HOT 8
- tensorflow-decision-forests 1.5.0 requires tensorflow~=2.13.0, but you have tensorflow 2.16.1 which is incompatible.
- Decision forest documentation link is broken in the Main page HOT 2
- WARNING:root:Failure to load the inference.so custom c++ tensorflow ops
- OOM errors for large datasets
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from decision-forests.