gbrl 1.0.0.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. gbrl-1.0.0.dev1/LICENSE +36 -0
  2. gbrl-1.0.0.dev1/MANIFEST.in +4 -0
  3. gbrl-1.0.0.dev1/PKG-INFO +11 -0
  4. gbrl-1.0.0.dev1/README.md +91 -0
  5. gbrl-1.0.0.dev1/gbrl/src/cpp/fitter.cpp +554 -0
  6. gbrl-1.0.0.dev1/gbrl/src/cpp/fitter.h +23 -0
  7. gbrl-1.0.0.dev1/gbrl/src/cpp/gbrl.cpp +939 -0
  8. gbrl-1.0.0.dev1/gbrl/src/cpp/gbrl.h +74 -0
  9. gbrl-1.0.0.dev1/gbrl/src/cpp/gbrl_binding.cpp +291 -0
  10. gbrl-1.0.0.dev1/gbrl/src/cpp/loss.cpp +64 -0
  11. gbrl-1.0.0.dev1/gbrl/src/cpp/loss.h +13 -0
  12. gbrl-1.0.0.dev1/gbrl/src/cpp/main.cpp +362 -0
  13. gbrl-1.0.0.dev1/gbrl/src/cpp/math_ops.cpp +602 -0
  14. gbrl-1.0.0.dev1/gbrl/src/cpp/math_ops.h +65 -0
  15. gbrl-1.0.0.dev1/gbrl/src/cpp/node.cpp +545 -0
  16. gbrl-1.0.0.dev1/gbrl/src/cpp/node.h +46 -0
  17. gbrl-1.0.0.dev1/gbrl/src/cpp/optimizer.cpp +292 -0
  18. gbrl-1.0.0.dev1/gbrl/src/cpp/optimizer.h +69 -0
  19. gbrl-1.0.0.dev1/gbrl/src/cpp/predictor.cpp +237 -0
  20. gbrl-1.0.0.dev1/gbrl/src/cpp/predictor.h +16 -0
  21. gbrl-1.0.0.dev1/gbrl/src/cpp/scheduler.cpp +106 -0
  22. gbrl-1.0.0.dev1/gbrl/src/cpp/scheduler.h +59 -0
  23. gbrl-1.0.0.dev1/gbrl/src/cpp/split_candidate_generator.cpp +305 -0
  24. gbrl-1.0.0.dev1/gbrl/src/cpp/split_candidate_generator.h +38 -0
  25. gbrl-1.0.0.dev1/gbrl/src/cpp/types.cpp +453 -0
  26. gbrl-1.0.0.dev1/gbrl/src/cpp/types.h +161 -0
  27. gbrl-1.0.0.dev1/gbrl/src/cpp/utils.cpp +30 -0
  28. gbrl-1.0.0.dev1/gbrl/src/cpp/utils.h +37 -0
  29. gbrl-1.0.0.dev1/gbrl/src/cuda/cuda_fitter.cu +1328 -0
  30. gbrl-1.0.0.dev1/gbrl/src/cuda/cuda_fitter.h +60 -0
  31. gbrl-1.0.0.dev1/gbrl/src/cuda/cuda_loss.cu +59 -0
  32. gbrl-1.0.0.dev1/gbrl/src/cuda/cuda_loss.h +21 -0
  33. gbrl-1.0.0.dev1/gbrl/src/cuda/cuda_predictor.cu +426 -0
  34. gbrl-1.0.0.dev1/gbrl/src/cuda/cuda_predictor.h +32 -0
  35. gbrl-1.0.0.dev1/gbrl/src/cuda/cuda_preprocess.cu +426 -0
  36. gbrl-1.0.0.dev1/gbrl/src/cuda/cuda_preprocess.h +33 -0
  37. gbrl-1.0.0.dev1/gbrl/src/cuda/cuda_types.cu +333 -0
  38. gbrl-1.0.0.dev1/gbrl/src/cuda/cuda_types.h +90 -0
  39. gbrl-1.0.0.dev1/gbrl/src/cuda/cuda_utils.cu +25 -0
  40. gbrl-1.0.0.dev1/gbrl/src/cuda/cuda_utils.h +16 -0
  41. gbrl-1.0.0.dev1/gbrl.egg-info/PKG-INFO +11 -0
  42. gbrl-1.0.0.dev1/gbrl.egg-info/SOURCES.txt +48 -0
  43. gbrl-1.0.0.dev1/gbrl.egg-info/dependency_links.txt +1 -0
  44. gbrl-1.0.0.dev1/gbrl.egg-info/requires.txt +6 -0
  45. gbrl-1.0.0.dev1/gbrl.egg-info/top_level.txt +1 -0
  46. gbrl-1.0.0.dev1/pyproject.toml +26 -0
  47. gbrl-1.0.0.dev1/setup.cfg +4 -0
  48. gbrl-1.0.0.dev1/setup.py +178 -0
  49. gbrl-1.0.0.dev1/tests/test_gbt_multi.py +561 -0
  50. gbrl-1.0.0.dev1/tests/test_gbt_single.py +559 -0
@@ -0,0 +1,36 @@
1
+ NVIDIA License
2
+
3
+ 1. Definitions
4
+
5
+ “Licensor” means any person or entity that distributes its Work.
6
+ “Work” means (a) the original work of authorship made available under this license, which may include software, documentation, or other files, and (b) any additions to or derivative works thereof that are made available under this license.
7
+ “NVIDIA Processors” means any central processing unit (CPU), graphics processing unit (GPU), field-programmable gate array (FPGA), application-specific integrated circuit (ASIC) or any combination thereof designed, made, sold, or provided by NVIDIA or its affiliates.
8
+ The terms “reproduce,” “reproduction,” “derivative works,” and “distribution” have the meaning as provided under U.S. copyright law; provided, however, that for the purposes of this license, derivative works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work.
9
+ Works are “made available” under this license by including in or with the Work either (a) a copyright notice referencing the applicability of this license to the Work, or (b) a copy of this license.
10
+
11
+ 2. License Grant
12
+
13
+ 2.1 Copyright Grant. Subject to the terms and conditions of this license, each Licensor grants to you a perpetual, worldwide, non-exclusive, royalty-free, copyright license to use, reproduce, prepare derivative works of, publicly display, publicly perform, sublicense and distribute its Work and any resulting derivative works in any form.
14
+
15
+ 3. Limitations
16
+
17
+ 3.1 Redistribution. You may reproduce or distribute the Work only if (a) you do so under this license, (b) you include a complete copy of this license with your distribution, and (c) you retain without modification any copyright, patent, trademark, or attribution notices that are present in the Work.
18
+
19
+ 3.2 Derivative Works. You may specify that additional or different terms apply to the use, reproduction, and distribution of your derivative works of the Work (“Your Terms”) only if (a) Your Terms provide that the use limitation in Section 3.3 applies to your derivative works, and (b) you identify the specific derivative works that are subject to Your Terms. Notwithstanding Your Terms, this license (including the redistribution requirements in Section 3.1) will continue to apply to the Work itself.
20
+
21
+ 3.3 Use Limitation. The Work and any derivative works thereof only may be used or intended for use non-commercially and with NVIDIA Processors. Notwithstanding the foregoing, NVIDIA Corporation and its affiliates may use the Work and any derivative works commercially. As used herein, “non-commercially” means for research or evaluation purposes only.
22
+
23
+ 3.4 Patent Claims. If you bring or threaten to bring a patent claim against any Licensor (including any claim, cross-claim or counterclaim in a lawsuit) to enforce any patents that you allege are infringed by any Work, then your rights under this license from such Licensor (including the grant in Section 2.1) will terminate immediately.
24
+
25
+ 3.5 Trademarks. This license does not grant any rights to use any Licensor’s or its affiliates’ names, logos, or trademarks, except as necessary to reproduce the notices described in this license.
26
+
27
+ 3.6 Termination. If you violate any term of this license, then your rights under this license (including the grant in Section 2.1) will terminate immediately.
28
+
29
+ 4. Disclaimer of Warranty.
30
+
31
+ THE WORK IS PROVIDED “AS IS” WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WARRANTIES OR CONDITIONS OF
32
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE OR NON-INFRINGEMENT. YOU BEAR THE RISK OF UNDERTAKING ANY ACTIVITIES UNDER THIS LICENSE.
33
+
34
+ 5. Limitation of Liability.
35
+
36
+ EXCEPT AS PROHIBITED BY APPLICABLE LAW, IN NO EVENT AND UNDER NO LEGAL THEORY, WHETHER IN TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE SHALL ANY LICENSOR BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATED TO THIS LICENSE, THE USE OR INABILITY TO USE THE WORK (INCLUDING BUT NOT LIMITED TO LOSS OF GOODWILL, BUSINESS INTERRUPTION, LOST PROFITS OR DATA, COMPUTER FAILURE OR MALFUNCTION, OR ANY OTHER DAMAGES OR LOSSES), EVEN IF THE LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
@@ -0,0 +1,4 @@
1
+ include gbrl/src/cuda/*.cu
2
+ include gbrl/src/cuda/*.h
3
+ include gbrl/src/cpp/*.cpp
4
+ include gbrl/src/cpp/*.h
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.1
2
+ Name: gbrl
3
+ Version: 1.0.0.dev1
4
+ Summary: Gradient Boosted Trees for RL
5
+ Author-email: Benjamin Fuhrer <bfuhrer@nvidia.com>, Chen Tesslr <ctessler@nvidia.com>, Gal Dalal <galal@nvidia.com>
6
+ License-File: LICENSE
7
+ Requires-Dist: pybind11==2.11.1
8
+ Requires-Dist: numpy
9
+ Requires-Dist: torch
10
+ Provides-Extra: sklearn
11
+ Requires-Dist: scikit_learn==1.2.2; extra == "sklearn"
@@ -0,0 +1,91 @@
1
+ # Gradient Boosting Reinforcement Learning (GBRL)
2
+ GBRL is a Python-based GBT library designed and optimized for reinforcement learning (RL). GBRL is implemented in C++/CUDA aimed to seamlessly integrate within popular RL libraries.
3
+
4
+ ### Key Features:
5
+ - GBTs Tailored for RL: GBRL adapts the power of Gradient Boosting Trees to the unique challenges of RL environments, including non-stationarity and delayed feedback.
6
+ - Optimized Actor-Critic Architecture: GBRL features a shared tree-based structure for policy and value functions. This significantly reduces memory and computational overhead, enabling it to tackle complex, high-dimensional RL problems.
7
+ - Hardware Acceleration: GBRL leverages CUDA for hardware-accelerated computation, ensuring efficiency and speed.
8
+ - Seamless Integration: GBRL is designed for easy integration with popular RL libraries, making it readily accessible for practitioners.
9
+
10
+
11
+ ## Getting started
12
+
13
+ ```
14
+ pip install gbrl
15
+ ```
16
+
17
+ For GPU support GBRL looks for `CUDA_PATH` or `CUDA_HOME` environment variables. Unless found, GBRL will automatically compile only for CPU.
18
+
19
+ Verify that GPU is visible by running
20
+ ```
21
+ import gbrl
22
+
23
+ gbrl.cuda_available()
24
+ ```
25
+
26
+ *OPTIONAL*
27
+ For tree visualization make sure graphviz is installed before compilation.
28
+
29
+ ## Usage Example in an RL library
30
+ ```
31
+ import torch as th
32
+ from gbrl import ActorCriticGBRL
33
+ from stable_baselines3.common.distributions import CategoricalDistribution
34
+
35
+ ### initialize model ###
36
+ # define tree structure parameters
37
+ tree_struct = {'max_depth': 4, 'min_data_in_leaf': 0, 'n_bins': 256, 'grow_policy': 'oblivious'}
38
+ # define gbrl parameters
39
+ gbrl_params = {'control_variates': False, 'split_score_func': 'cosine', 'generator_type': 'Quantile'}
40
+ # actor and critic optimizers
41
+ policy_optimizer = {'algo': 'SGD', 'lr': 0.05}
42
+ value_optimizer = {'algo': 'SGD', lr: '0.25'}
43
+
44
+ # Given action_space instance of gym.spaces.Space
45
+
46
+ model = ActorCriticGBRL(tree_struct=tree_struct, output_dim=action_space.n, pg_optimizer=policy_optimizer, value_optimizer=value_optimizer, shared_tree_struct=True, gbrl_params=gbrl_params, device='cuda')
47
+ model.init_model()
48
+
49
+ action_dist = CategoricalDistribution(action_space.n)
50
+ ### Training loop ###
51
+ logits, values = model(obs) # returns numpy arrays
52
+ logits = th.tensor(logits, requires_grad=True)
53
+ values = th.tensor(values, requires_grad=True)
54
+
55
+ distribution = action_dist.proba_distribution(logits)
56
+ log_prob = distribution.log_prob(actions)
57
+
58
+ loss = ... calculate loss according to RL algorithm
59
+
60
+ loss.backward()
61
+
62
+ self.policy.fit(rollout_data., theta_grad, values_grad)
63
+
64
+ # calculate grads (GBRL fits numpy arrays)
65
+ logits_grads = logits.grad.detach().cpu().numpy() * len(obs) # gradients w.r.t to the *each sample
66
+ value_grads = values.grad.detach().cpu().numpy() * len(obs)
67
+
68
+ model.fit(obs, logits_grads, value_grads)
69
+ ```
70
+
71
+ ## Current Supported Features
72
+ ### Tree Fitting
73
+ - Greedy (Depth-wise) tree building - (CPU/GPU)
74
+ - Oblivious (Symmetric) tree building - (CPU/GPU)
75
+ - L2 split score - (CPU/GPU)
76
+ - Cosine split score - (CPU/GPU)
77
+ - Uniform based candidate generation - (CPU/GPU)
78
+ - Quantile based candidate generation - (CPU/GPU)
79
+ - Supervised learning fitting / Multi-iteration fitting - (CPU/GPU)
80
+ - MultiRMSE loss (only)
81
+ - Categorical Inputs
82
+ ### GBT Inference
83
+ - SGD optimizer - (CPU/GPU)
84
+ - ADAM optimizer - (CPU only)
85
+ - Control Variates (gradient variance reduction technique) - (CPU only)
86
+ - Shared Tree for policy and value function - (CPU/GPU)
87
+ - Linear and constant learning rate scheduler - (CPU/GPU only constant)
88
+ - Support for up to two different optimizers (e.g, policy/value) - **(CPU/GPU if both are SGD)
89
+
90
+ ## Citing
91
+