Giter VIP home page Giter VIP logo

Comments (2)

achoum avatar achoum commented on May 21, 2024

Hi Frankwwu

Thanks for the post. There might be different things in play. Following are some possible explanation & solutions:

  1. 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.

  1. 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.

  1. 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.

  1. 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.

  1. 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.

achoum avatar achoum commented on May 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.