Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/ops/gen_boosted_trees_ops.py: 9%
1254 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
1"""Python wrappers around TensorFlow ops.
3This file is MACHINE GENERATED! Do not edit.
4"""
6import collections
8from tensorflow.python import pywrap_tfe as pywrap_tfe
9from tensorflow.python.eager import context as _context
10from tensorflow.python.eager import core as _core
11from tensorflow.python.eager import execute as _execute
12from tensorflow.python.framework import dtypes as _dtypes
13from tensorflow.security.fuzzing.py import annotation_types as _atypes
15from tensorflow.python.framework import op_def_registry as _op_def_registry
16from tensorflow.python.framework import ops as _ops
17from tensorflow.python.framework import op_def_library as _op_def_library
18from tensorflow.python.util.deprecation import deprecated_endpoints
19from tensorflow.python.util import dispatch as _dispatch
20from tensorflow.python.util.tf_export import tf_export
22from typing import TypeVar
24def boosted_trees_aggregate_stats(node_ids, gradients, hessians, feature, max_splits, num_buckets, name=None):
25 r"""Aggregates the summary of accumulated stats for the batch.
27 The summary stats contains gradients and hessians accumulated for each node, feature dimension id and bucket.
29 Args:
30 node_ids: A `Tensor` of type `int32`.
31 int32; Rank 1 Tensor containing node ids for each example, shape [batch_size].
32 gradients: A `Tensor` of type `float32`.
33 float32; Rank 2 Tensor (shape=[batch_size, logits_dimension]) with gradients for each example.
34 hessians: A `Tensor` of type `float32`.
35 float32; Rank 2 Tensor (shape=[batch_size, hessian_dimension]) with hessians for each example.
36 feature: A `Tensor` of type `int32`.
37 int32; Rank 2 feature Tensors (shape=[batch_size, feature_dimension]).
38 max_splits: An `int` that is `>= 1`.
39 int; the maximum number of splits possible in the whole tree.
40 num_buckets: An `int` that is `>= 1`.
41 int; equals to the maximum possible value of bucketized feature.
42 name: A name for the operation (optional).
44 Returns:
45 A `Tensor` of type `float32`.
46 """
47 _ctx = _context._context or _context.context()
48 tld = _ctx._thread_local_data
49 if tld.is_eager:
50 try:
51 _result = pywrap_tfe.TFE_Py_FastPathExecute(
52 _ctx, "BoostedTreesAggregateStats", name, node_ids, gradients,
53 hessians, feature, "max_splits", max_splits, "num_buckets",
54 num_buckets)
55 return _result
56 except _core._NotOkStatusException as e:
57 _ops.raise_from_not_ok_status(e, name)
58 except _core._FallbackException:
59 pass
60 try:
61 return boosted_trees_aggregate_stats_eager_fallback(
62 node_ids, gradients, hessians, feature, max_splits=max_splits,
63 num_buckets=num_buckets, name=name, ctx=_ctx)
64 except _core._SymbolicException:
65 pass # Add nodes to the TensorFlow graph.
66 # Add nodes to the TensorFlow graph.
67 max_splits = _execute.make_int(max_splits, "max_splits")
68 num_buckets = _execute.make_int(num_buckets, "num_buckets")
69 _, _, _op, _outputs = _op_def_library._apply_op_helper(
70 "BoostedTreesAggregateStats", node_ids=node_ids, gradients=gradients,
71 hessians=hessians, feature=feature,
72 max_splits=max_splits,
73 num_buckets=num_buckets, name=name)
74 _result = _outputs[:]
75 if _execute.must_record_gradient():
76 _attrs = ("max_splits", _op._get_attr_int("max_splits"), "num_buckets",
77 _op._get_attr_int("num_buckets"))
78 _inputs_flat = _op.inputs
79 _execute.record_gradient(
80 "BoostedTreesAggregateStats", _inputs_flat, _attrs, _result)
81 _result, = _result
82 return _result
84BoostedTreesAggregateStats = tf_export("raw_ops.BoostedTreesAggregateStats")(_ops.to_raw_op(boosted_trees_aggregate_stats))
87def boosted_trees_aggregate_stats_eager_fallback(node_ids, gradients, hessians, feature, max_splits, num_buckets, name, ctx):
88 max_splits = _execute.make_int(max_splits, "max_splits")
89 num_buckets = _execute.make_int(num_buckets, "num_buckets")
90 node_ids = _ops.convert_to_tensor(node_ids, _dtypes.int32)
91 gradients = _ops.convert_to_tensor(gradients, _dtypes.float32)
92 hessians = _ops.convert_to_tensor(hessians, _dtypes.float32)
93 feature = _ops.convert_to_tensor(feature, _dtypes.int32)
94 _inputs_flat = [node_ids, gradients, hessians, feature]
95 _attrs = ("max_splits", max_splits, "num_buckets", num_buckets)
96 _result = _execute.execute(b"BoostedTreesAggregateStats", 1,
97 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
98 name=name)
99 if _execute.must_record_gradient():
100 _execute.record_gradient(
101 "BoostedTreesAggregateStats", _inputs_flat, _attrs, _result)
102 _result, = _result
103 return _result
106def boosted_trees_bucketize(float_values, bucket_boundaries, name=None):
107 r"""Bucketize each feature based on bucket boundaries.
109 An op that returns a list of float tensors, where each tensor represents the
110 bucketized values for a single feature.
112 Args:
113 float_values: A list of `Tensor` objects with type `float32`.
114 float; List of Rank 1 Tensor each containing float values for a single feature.
115 bucket_boundaries: A list with the same length as `float_values` of `Tensor` objects with type `float32`.
116 float; List of Rank 1 Tensors each containing the bucket boundaries for a single
117 feature.
118 name: A name for the operation (optional).
120 Returns:
121 A list with the same length as `float_values` of `Tensor` objects with type `int32`.
122 """
123 _ctx = _context._context or _context.context()
124 tld = _ctx._thread_local_data
125 if tld.is_eager:
126 try:
127 _result = pywrap_tfe.TFE_Py_FastPathExecute(
128 _ctx, "BoostedTreesBucketize", name, float_values, bucket_boundaries)
129 return _result
130 except _core._NotOkStatusException as e:
131 _ops.raise_from_not_ok_status(e, name)
132 except _core._FallbackException:
133 pass
134 try:
135 return boosted_trees_bucketize_eager_fallback(
136 float_values, bucket_boundaries, name=name, ctx=_ctx)
137 except _core._SymbolicException:
138 pass # Add nodes to the TensorFlow graph.
139 # Add nodes to the TensorFlow graph.
140 if not isinstance(float_values, (list, tuple)):
141 raise TypeError(
142 "Expected list for 'float_values' argument to "
143 "'boosted_trees_bucketize' Op, not %r." % float_values)
144 _attr_num_features = len(float_values)
145 if not isinstance(bucket_boundaries, (list, tuple)):
146 raise TypeError(
147 "Expected list for 'bucket_boundaries' argument to "
148 "'boosted_trees_bucketize' Op, not %r." % bucket_boundaries)
149 if len(bucket_boundaries) != _attr_num_features:
150 raise ValueError(
151 "List argument 'bucket_boundaries' to 'boosted_trees_bucketize' Op with length %d "
152 "must match length %d of argument 'float_values'." %
153 (len(bucket_boundaries), _attr_num_features))
154 _, _, _op, _outputs = _op_def_library._apply_op_helper(
155 "BoostedTreesBucketize", float_values=float_values,
156 bucket_boundaries=bucket_boundaries,
157 name=name)
158 _result = _outputs[:]
159 if _execute.must_record_gradient():
160 _attrs = ("num_features", _op._get_attr_int("num_features"))
161 _inputs_flat = _op.inputs
162 _execute.record_gradient(
163 "BoostedTreesBucketize", _inputs_flat, _attrs, _result)
164 return _result
166BoostedTreesBucketize = tf_export("raw_ops.BoostedTreesBucketize")(_ops.to_raw_op(boosted_trees_bucketize))
169def boosted_trees_bucketize_eager_fallback(float_values, bucket_boundaries, name, ctx):
170 if not isinstance(float_values, (list, tuple)):
171 raise TypeError(
172 "Expected list for 'float_values' argument to "
173 "'boosted_trees_bucketize' Op, not %r." % float_values)
174 _attr_num_features = len(float_values)
175 if not isinstance(bucket_boundaries, (list, tuple)):
176 raise TypeError(
177 "Expected list for 'bucket_boundaries' argument to "
178 "'boosted_trees_bucketize' Op, not %r." % bucket_boundaries)
179 if len(bucket_boundaries) != _attr_num_features:
180 raise ValueError(
181 "List argument 'bucket_boundaries' to 'boosted_trees_bucketize' Op with length %d "
182 "must match length %d of argument 'float_values'." %
183 (len(bucket_boundaries), _attr_num_features))
184 float_values = _ops.convert_n_to_tensor(float_values, _dtypes.float32)
185 bucket_boundaries = _ops.convert_n_to_tensor(bucket_boundaries, _dtypes.float32)
186 _inputs_flat = list(float_values) + list(bucket_boundaries)
187 _attrs = ("num_features", _attr_num_features)
188 _result = _execute.execute(b"BoostedTreesBucketize", _attr_num_features,
189 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
190 name=name)
191 if _execute.must_record_gradient():
192 _execute.record_gradient(
193 "BoostedTreesBucketize", _inputs_flat, _attrs, _result)
194 return _result
196_BoostedTreesCalculateBestFeatureSplitOutput = collections.namedtuple(
197 "BoostedTreesCalculateBestFeatureSplit",
198 ["node_ids", "gains", "feature_dimensions", "thresholds", "left_node_contribs", "right_node_contribs", "split_with_default_directions"])
201def boosted_trees_calculate_best_feature_split(node_id_range, stats_summary, l1, l2, tree_complexity, min_node_weight, logits_dimension, split_type="inequality", name=None):
202 r"""Calculates gains for each feature and returns the best possible split information for the feature.
204 The split information is the best threshold (bucket id), gains and left/right node contributions per node for each feature.
206 It is possible that not all nodes can be split on each feature. Hence, the list of possible nodes can differ between the features. Therefore, we return `node_ids_list` for each feature, containing the list of nodes that this feature can be used to split.
208 In this manner, the output is the best split per features and per node, so that it needs to be combined later to produce the best split for each node (among all possible features).
210 The output shapes are compatible in a way that the first dimension of all tensors are the same and equal to the number of possible split nodes for each feature.
212 Args:
213 node_id_range: A `Tensor` of type `int32`.
214 A Rank 1 tensor (shape=[2]) to specify the range [first, last) of node ids to process within `stats_summary_list`. The nodes are iterated between the two nodes specified by the tensor, as like `for node_id in range(node_id_range[0], node_id_range[1])` (Note that the last index node_id_range[1] is exclusive).
215 stats_summary: A `Tensor` of type `float32`.
216 A Rank 4 tensor (#shape=[max_splits, feature_dims, bucket, stats_dims]) for accumulated stats summary (gradient/hessian) per node, per dimension, per buckets for each feature.
217 The first dimension of the tensor is the maximum number of splits, and thus not all elements of it will be used, but only the indexes specified by node_ids will be used.
218 l1: A `Tensor` of type `float32`.
219 l1 regularization factor on leaf weights, per instance based.
220 l2: A `Tensor` of type `float32`.
221 l2 regularization factor on leaf weights, per instance based.
222 tree_complexity: A `Tensor` of type `float32`.
223 adjustment to the gain, per leaf based.
224 min_node_weight: A `Tensor` of type `float32`.
225 minimum avg of hessians in a node before required for the node to be considered for splitting.
226 logits_dimension: An `int` that is `>= 1`.
227 The dimension of logit, i.e., number of classes.
228 split_type: An optional `string` from: `"inequality", "equality"`. Defaults to `"inequality"`.
229 A string indicating if this Op should perform inequality split or equality split.
230 name: A name for the operation (optional).
232 Returns:
233 A tuple of `Tensor` objects (node_ids, gains, feature_dimensions, thresholds, left_node_contribs, right_node_contribs, split_with_default_directions).
235 node_ids: A `Tensor` of type `int32`.
236 gains: A `Tensor` of type `float32`.
237 feature_dimensions: A `Tensor` of type `int32`.
238 thresholds: A `Tensor` of type `int32`.
239 left_node_contribs: A `Tensor` of type `float32`.
240 right_node_contribs: A `Tensor` of type `float32`.
241 split_with_default_directions: A `Tensor` of type `string`.
242 """
243 _ctx = _context._context or _context.context()
244 tld = _ctx._thread_local_data
245 if tld.is_eager:
246 try:
247 _result = pywrap_tfe.TFE_Py_FastPathExecute(
248 _ctx, "BoostedTreesCalculateBestFeatureSplit", name, node_id_range,
249 stats_summary, l1, l2, tree_complexity, min_node_weight,
250 "logits_dimension", logits_dimension, "split_type", split_type)
251 _result = _BoostedTreesCalculateBestFeatureSplitOutput._make(_result)
252 return _result
253 except _core._NotOkStatusException as e:
254 _ops.raise_from_not_ok_status(e, name)
255 except _core._FallbackException:
256 pass
257 try:
258 return boosted_trees_calculate_best_feature_split_eager_fallback(
259 node_id_range, stats_summary, l1, l2, tree_complexity,
260 min_node_weight, logits_dimension=logits_dimension,
261 split_type=split_type, name=name, ctx=_ctx)
262 except _core._SymbolicException:
263 pass # Add nodes to the TensorFlow graph.
264 # Add nodes to the TensorFlow graph.
265 logits_dimension = _execute.make_int(logits_dimension, "logits_dimension")
266 if split_type is None:
267 split_type = "inequality"
268 split_type = _execute.make_str(split_type, "split_type")
269 _, _, _op, _outputs = _op_def_library._apply_op_helper(
270 "BoostedTreesCalculateBestFeatureSplit", node_id_range=node_id_range,
271 stats_summary=stats_summary,
272 l1=l1, l2=l2,
273 tree_complexity=tree_complexity,
274 min_node_weight=min_node_weight,
275 logits_dimension=logits_dimension,
276 split_type=split_type,
277 name=name)
278 _result = _outputs[:]
279 if _execute.must_record_gradient():
280 _attrs = ("logits_dimension", _op._get_attr_int("logits_dimension"),
281 "split_type", _op.get_attr("split_type"))
282 _inputs_flat = _op.inputs
283 _execute.record_gradient(
284 "BoostedTreesCalculateBestFeatureSplit", _inputs_flat, _attrs, _result)
285 _result = _BoostedTreesCalculateBestFeatureSplitOutput._make(_result)
286 return _result
288BoostedTreesCalculateBestFeatureSplit = tf_export("raw_ops.BoostedTreesCalculateBestFeatureSplit")(_ops.to_raw_op(boosted_trees_calculate_best_feature_split))
291def boosted_trees_calculate_best_feature_split_eager_fallback(node_id_range, stats_summary, l1, l2, tree_complexity, min_node_weight, logits_dimension, split_type, name, ctx):
292 logits_dimension = _execute.make_int(logits_dimension, "logits_dimension")
293 if split_type is None:
294 split_type = "inequality"
295 split_type = _execute.make_str(split_type, "split_type")
296 node_id_range = _ops.convert_to_tensor(node_id_range, _dtypes.int32)
297 stats_summary = _ops.convert_to_tensor(stats_summary, _dtypes.float32)
298 l1 = _ops.convert_to_tensor(l1, _dtypes.float32)
299 l2 = _ops.convert_to_tensor(l2, _dtypes.float32)
300 tree_complexity = _ops.convert_to_tensor(tree_complexity, _dtypes.float32)
301 min_node_weight = _ops.convert_to_tensor(min_node_weight, _dtypes.float32)
302 _inputs_flat = [node_id_range, stats_summary, l1, l2, tree_complexity, min_node_weight]
303 _attrs = ("logits_dimension", logits_dimension, "split_type", split_type)
304 _result = _execute.execute(b"BoostedTreesCalculateBestFeatureSplit", 7,
305 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
306 name=name)
307 if _execute.must_record_gradient():
308 _execute.record_gradient(
309 "BoostedTreesCalculateBestFeatureSplit", _inputs_flat, _attrs, _result)
310 _result = _BoostedTreesCalculateBestFeatureSplitOutput._make(_result)
311 return _result
313_BoostedTreesCalculateBestFeatureSplitV2Output = collections.namedtuple(
314 "BoostedTreesCalculateBestFeatureSplitV2",
315 ["node_ids", "gains", "feature_ids", "feature_dimensions", "thresholds", "left_node_contribs", "right_node_contribs", "split_with_default_directions"])
318def boosted_trees_calculate_best_feature_split_v2(node_id_range, stats_summaries_list, split_types, candidate_feature_ids, l1, l2, tree_complexity, min_node_weight, logits_dimension, name=None):
319 r"""Calculates gains for each feature and returns the best possible split information for each node. However, if no split is found, then no split information is returned for that node.
321 The split information is the best threshold (bucket id), gains and left/right node contributions per node for each feature.
323 It is possible that not all nodes can be split on each feature. Hence, the list of possible nodes can differ between the features. Therefore, we return `node_ids_list` for each feature, containing the list of nodes that this feature can be used to split.
325 In this manner, the output is the best split per features and per node, so that it needs to be combined later to produce the best split for each node (among all possible features).
327 The output shapes are compatible in a way that the first dimension of all tensors are the same and equal to the number of possible split nodes for each feature.
329 Args:
330 node_id_range: A `Tensor` of type `int32`.
331 A Rank 1 tensor (shape=[2]) to specify the range [first, last) of node ids to process within `stats_summary_list`. The nodes are iterated between the two nodes specified by the tensor, as like `for node_id in range(node_id_range[0], node_id_range[1])` (Note that the last index node_id_range[1] is exclusive).
332 stats_summaries_list: A list of at least 1 `Tensor` objects with type `float32`.
333 A list of Rank 4 tensor (#shape=[max_splits, feature_dims, bucket, stats_dims]) for accumulated stats summary (gradient/hessian) per node, per dimension, per buckets for each feature.
334 The first dimension of the tensor is the maximum number of splits, and thus not all elements of it will be used, but only the indexes specified by node_ids will be used.
335 split_types: A `Tensor` of type `string`.
336 A Rank 1 tensor indicating if this Op should perform inequality split or equality split per feature.
337 candidate_feature_ids: A `Tensor` of type `int32`.
338 Rank 1 tensor with ids for each feature. This is the real id of the feature.
339 l1: A `Tensor` of type `float32`.
340 l1 regularization factor on leaf weights, per instance based.
341 l2: A `Tensor` of type `float32`.
342 l2 regularization factor on leaf weights, per instance based.
343 tree_complexity: A `Tensor` of type `float32`.
344 adjustment to the gain, per leaf based.
345 min_node_weight: A `Tensor` of type `float32`.
346 minimum avg of hessians in a node before required for the node to be considered for splitting.
347 logits_dimension: An `int` that is `>= 1`.
348 The dimension of logit, i.e., number of classes.
349 name: A name for the operation (optional).
351 Returns:
352 A tuple of `Tensor` objects (node_ids, gains, feature_ids, feature_dimensions, thresholds, left_node_contribs, right_node_contribs, split_with_default_directions).
354 node_ids: A `Tensor` of type `int32`.
355 gains: A `Tensor` of type `float32`.
356 feature_ids: A `Tensor` of type `int32`.
357 feature_dimensions: A `Tensor` of type `int32`.
358 thresholds: A `Tensor` of type `int32`.
359 left_node_contribs: A `Tensor` of type `float32`.
360 right_node_contribs: A `Tensor` of type `float32`.
361 split_with_default_directions: A `Tensor` of type `string`.
362 """
363 _ctx = _context._context or _context.context()
364 tld = _ctx._thread_local_data
365 if tld.is_eager:
366 try:
367 _result = pywrap_tfe.TFE_Py_FastPathExecute(
368 _ctx, "BoostedTreesCalculateBestFeatureSplitV2", name, node_id_range,
369 stats_summaries_list, split_types, candidate_feature_ids, l1, l2,
370 tree_complexity, min_node_weight, "logits_dimension",
371 logits_dimension)
372 _result = _BoostedTreesCalculateBestFeatureSplitV2Output._make(_result)
373 return _result
374 except _core._NotOkStatusException as e:
375 _ops.raise_from_not_ok_status(e, name)
376 except _core._FallbackException:
377 pass
378 try:
379 return boosted_trees_calculate_best_feature_split_v2_eager_fallback(
380 node_id_range, stats_summaries_list, split_types,
381 candidate_feature_ids, l1, l2, tree_complexity, min_node_weight,
382 logits_dimension=logits_dimension, name=name, ctx=_ctx)
383 except _core._SymbolicException:
384 pass # Add nodes to the TensorFlow graph.
385 # Add nodes to the TensorFlow graph.
386 if not isinstance(stats_summaries_list, (list, tuple)):
387 raise TypeError(
388 "Expected list for 'stats_summaries_list' argument to "
389 "'boosted_trees_calculate_best_feature_split_v2' Op, not %r." % stats_summaries_list)
390 _attr_num_features = len(stats_summaries_list)
391 logits_dimension = _execute.make_int(logits_dimension, "logits_dimension")
392 _, _, _op, _outputs = _op_def_library._apply_op_helper(
393 "BoostedTreesCalculateBestFeatureSplitV2", node_id_range=node_id_range,
394 stats_summaries_list=stats_summaries_list,
395 split_types=split_types,
396 candidate_feature_ids=candidate_feature_ids,
397 l1=l1, l2=l2,
398 tree_complexity=tree_complexity,
399 min_node_weight=min_node_weight,
400 logits_dimension=logits_dimension,
401 name=name)
402 _result = _outputs[:]
403 if _execute.must_record_gradient():
404 _attrs = ("num_features", _op._get_attr_int("num_features"),
405 "logits_dimension", _op._get_attr_int("logits_dimension"))
406 _inputs_flat = _op.inputs
407 _execute.record_gradient(
408 "BoostedTreesCalculateBestFeatureSplitV2", _inputs_flat, _attrs, _result)
409 _result = _BoostedTreesCalculateBestFeatureSplitV2Output._make(_result)
410 return _result
412BoostedTreesCalculateBestFeatureSplitV2 = tf_export("raw_ops.BoostedTreesCalculateBestFeatureSplitV2")(_ops.to_raw_op(boosted_trees_calculate_best_feature_split_v2))
415def boosted_trees_calculate_best_feature_split_v2_eager_fallback(node_id_range, stats_summaries_list, split_types, candidate_feature_ids, l1, l2, tree_complexity, min_node_weight, logits_dimension, name, ctx):
416 if not isinstance(stats_summaries_list, (list, tuple)):
417 raise TypeError(
418 "Expected list for 'stats_summaries_list' argument to "
419 "'boosted_trees_calculate_best_feature_split_v2' Op, not %r." % stats_summaries_list)
420 _attr_num_features = len(stats_summaries_list)
421 logits_dimension = _execute.make_int(logits_dimension, "logits_dimension")
422 node_id_range = _ops.convert_to_tensor(node_id_range, _dtypes.int32)
423 stats_summaries_list = _ops.convert_n_to_tensor(stats_summaries_list, _dtypes.float32)
424 split_types = _ops.convert_to_tensor(split_types, _dtypes.string)
425 candidate_feature_ids = _ops.convert_to_tensor(candidate_feature_ids, _dtypes.int32)
426 l1 = _ops.convert_to_tensor(l1, _dtypes.float32)
427 l2 = _ops.convert_to_tensor(l2, _dtypes.float32)
428 tree_complexity = _ops.convert_to_tensor(tree_complexity, _dtypes.float32)
429 min_node_weight = _ops.convert_to_tensor(min_node_weight, _dtypes.float32)
430 _inputs_flat = [node_id_range] + list(stats_summaries_list) + [split_types, candidate_feature_ids, l1, l2, tree_complexity, min_node_weight]
431 _attrs = ("num_features", _attr_num_features, "logits_dimension",
432 logits_dimension)
433 _result = _execute.execute(b"BoostedTreesCalculateBestFeatureSplitV2", 8,
434 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
435 name=name)
436 if _execute.must_record_gradient():
437 _execute.record_gradient(
438 "BoostedTreesCalculateBestFeatureSplitV2", _inputs_flat, _attrs, _result)
439 _result = _BoostedTreesCalculateBestFeatureSplitV2Output._make(_result)
440 return _result
442_BoostedTreesCalculateBestGainsPerFeatureOutput = collections.namedtuple(
443 "BoostedTreesCalculateBestGainsPerFeature",
444 ["node_ids_list", "gains_list", "thresholds_list", "left_node_contribs_list", "right_node_contribs_list"])
447def boosted_trees_calculate_best_gains_per_feature(node_id_range, stats_summary_list, l1, l2, tree_complexity, min_node_weight, max_splits, name=None):
448 r"""Calculates gains for each feature and returns the best possible split information for the feature.
450 The split information is the best threshold (bucket id), gains and left/right node contributions per node for each feature.
452 It is possible that not all nodes can be split on each feature. Hence, the list of possible nodes can differ between the features. Therefore, we return `node_ids_list` for each feature, containing the list of nodes that this feature can be used to split.
454 In this manner, the output is the best split per features and per node, so that it needs to be combined later to produce the best split for each node (among all possible features).
456 The length of output lists are all of the same length, `num_features`.
457 The output shapes are compatible in a way that the first dimension of all tensors of all lists are the same and equal to the number of possible split nodes for each feature.
459 Args:
460 node_id_range: A `Tensor` of type `int32`.
461 A Rank 1 tensor (shape=[2]) to specify the range [first, last) of node ids to process within `stats_summary_list`. The nodes are iterated between the two nodes specified by the tensor, as like `for node_id in range(node_id_range[0], node_id_range[1])` (Note that the last index node_id_range[1] is exclusive).
462 stats_summary_list: A list of at least 1 `Tensor` objects with type `float32`.
463 A list of Rank 3 tensor (#shape=[max_splits, bucket, 2]) for accumulated stats summary (gradient/hessian) per node per buckets for each feature. The first dimension of the tensor is the maximum number of splits, and thus not all elements of it will be used, but only the indexes specified by node_ids will be used.
464 l1: A `Tensor` of type `float32`.
465 l1 regularization factor on leaf weights, per instance based.
466 l2: A `Tensor` of type `float32`.
467 l2 regularization factor on leaf weights, per instance based.
468 tree_complexity: A `Tensor` of type `float32`.
469 adjustment to the gain, per leaf based.
470 min_node_weight: A `Tensor` of type `float32`.
471 minimum avg of hessians in a node before required for the node to be considered for splitting.
472 max_splits: An `int` that is `>= 1`.
473 the number of nodes that can be split in the whole tree. Used as a dimension of output tensors.
474 name: A name for the operation (optional).
476 Returns:
477 A tuple of `Tensor` objects (node_ids_list, gains_list, thresholds_list, left_node_contribs_list, right_node_contribs_list).
479 node_ids_list: A list with the same length as `stats_summary_list` of `Tensor` objects with type `int32`.
480 gains_list: A list with the same length as `stats_summary_list` of `Tensor` objects with type `float32`.
481 thresholds_list: A list with the same length as `stats_summary_list` of `Tensor` objects with type `int32`.
482 left_node_contribs_list: A list with the same length as `stats_summary_list` of `Tensor` objects with type `float32`.
483 right_node_contribs_list: A list with the same length as `stats_summary_list` of `Tensor` objects with type `float32`.
484 """
485 _ctx = _context._context or _context.context()
486 tld = _ctx._thread_local_data
487 if tld.is_eager:
488 try:
489 _result = pywrap_tfe.TFE_Py_FastPathExecute(
490 _ctx, "BoostedTreesCalculateBestGainsPerFeature", name, node_id_range,
491 stats_summary_list, l1, l2, tree_complexity, min_node_weight,
492 "max_splits", max_splits)
493 _result = _BoostedTreesCalculateBestGainsPerFeatureOutput._make(_result)
494 return _result
495 except _core._NotOkStatusException as e:
496 _ops.raise_from_not_ok_status(e, name)
497 except _core._FallbackException:
498 pass
499 try:
500 return boosted_trees_calculate_best_gains_per_feature_eager_fallback(
501 node_id_range, stats_summary_list, l1, l2, tree_complexity,
502 min_node_weight, max_splits=max_splits, name=name, ctx=_ctx)
503 except _core._SymbolicException:
504 pass # Add nodes to the TensorFlow graph.
505 # Add nodes to the TensorFlow graph.
506 if not isinstance(stats_summary_list, (list, tuple)):
507 raise TypeError(
508 "Expected list for 'stats_summary_list' argument to "
509 "'boosted_trees_calculate_best_gains_per_feature' Op, not %r." % stats_summary_list)
510 _attr_num_features = len(stats_summary_list)
511 max_splits = _execute.make_int(max_splits, "max_splits")
512 _, _, _op, _outputs = _op_def_library._apply_op_helper(
513 "BoostedTreesCalculateBestGainsPerFeature", node_id_range=node_id_range,
514 stats_summary_list=stats_summary_list,
515 l1=l1, l2=l2,
516 tree_complexity=tree_complexity,
517 min_node_weight=min_node_weight,
518 max_splits=max_splits,
519 name=name)
520 _result = _outputs[:]
521 if _execute.must_record_gradient():
522 _attrs = ("max_splits", _op._get_attr_int("max_splits"), "num_features",
523 _op._get_attr_int("num_features"))
524 _inputs_flat = _op.inputs
525 _execute.record_gradient(
526 "BoostedTreesCalculateBestGainsPerFeature", _inputs_flat, _attrs, _result)
527 _result = [_result[:_attr_num_features]] + _result[_attr_num_features:]
528 _result = _result[:1] + [_result[1:1 + _attr_num_features]] + _result[1 + _attr_num_features:]
529 _result = _result[:2] + [_result[2:2 + _attr_num_features]] + _result[2 + _attr_num_features:]
530 _result = _result[:3] + [_result[3:3 + _attr_num_features]] + _result[3 + _attr_num_features:]
531 _result = _result[:4] + [_result[4:]]
532 _result = _BoostedTreesCalculateBestGainsPerFeatureOutput._make(_result)
533 return _result
535BoostedTreesCalculateBestGainsPerFeature = tf_export("raw_ops.BoostedTreesCalculateBestGainsPerFeature")(_ops.to_raw_op(boosted_trees_calculate_best_gains_per_feature))
538def boosted_trees_calculate_best_gains_per_feature_eager_fallback(node_id_range, stats_summary_list, l1, l2, tree_complexity, min_node_weight, max_splits, name, ctx):
539 if not isinstance(stats_summary_list, (list, tuple)):
540 raise TypeError(
541 "Expected list for 'stats_summary_list' argument to "
542 "'boosted_trees_calculate_best_gains_per_feature' Op, not %r." % stats_summary_list)
543 _attr_num_features = len(stats_summary_list)
544 max_splits = _execute.make_int(max_splits, "max_splits")
545 node_id_range = _ops.convert_to_tensor(node_id_range, _dtypes.int32)
546 stats_summary_list = _ops.convert_n_to_tensor(stats_summary_list, _dtypes.float32)
547 l1 = _ops.convert_to_tensor(l1, _dtypes.float32)
548 l2 = _ops.convert_to_tensor(l2, _dtypes.float32)
549 tree_complexity = _ops.convert_to_tensor(tree_complexity, _dtypes.float32)
550 min_node_weight = _ops.convert_to_tensor(min_node_weight, _dtypes.float32)
551 _inputs_flat = [node_id_range] + list(stats_summary_list) + [l1, l2, tree_complexity, min_node_weight]
552 _attrs = ("max_splits", max_splits, "num_features", _attr_num_features)
553 _result = _execute.execute(b"BoostedTreesCalculateBestGainsPerFeature",
554 _attr_num_features + _attr_num_features +
555 _attr_num_features + _attr_num_features +
556 _attr_num_features, inputs=_inputs_flat,
557 attrs=_attrs, ctx=ctx, name=name)
558 if _execute.must_record_gradient():
559 _execute.record_gradient(
560 "BoostedTreesCalculateBestGainsPerFeature", _inputs_flat, _attrs, _result)
561 _result = [_result[:_attr_num_features]] + _result[_attr_num_features:]
562 _result = _result[:1] + [_result[1:1 + _attr_num_features]] + _result[1 + _attr_num_features:]
563 _result = _result[:2] + [_result[2:2 + _attr_num_features]] + _result[2 + _attr_num_features:]
564 _result = _result[:3] + [_result[3:3 + _attr_num_features]] + _result[3 + _attr_num_features:]
565 _result = _result[:4] + [_result[4:]]
566 _result = _BoostedTreesCalculateBestGainsPerFeatureOutput._make(_result)
567 return _result
570def boosted_trees_center_bias(tree_ensemble_handle, mean_gradients, mean_hessians, l1, l2, name=None):
571 r"""Calculates the prior from the training data (the bias) and fills in the first node with the logits' prior. Returns a boolean indicating whether to continue centering.
573 Args:
574 tree_ensemble_handle: A `Tensor` of type `resource`.
575 Handle to the tree ensemble.
576 mean_gradients: A `Tensor` of type `float32`.
577 A tensor with shape=[logits_dimension] with mean of gradients for a first node.
578 mean_hessians: A `Tensor` of type `float32`.
579 A tensor with shape=[logits_dimension] mean of hessians for a first node.
580 l1: A `Tensor` of type `float32`.
581 l1 regularization factor on leaf weights, per instance based.
582 l2: A `Tensor` of type `float32`.
583 l2 regularization factor on leaf weights, per instance based.
584 name: A name for the operation (optional).
586 Returns:
587 A `Tensor` of type `bool`.
588 """
589 _ctx = _context._context or _context.context()
590 tld = _ctx._thread_local_data
591 if tld.is_eager:
592 try:
593 _result = pywrap_tfe.TFE_Py_FastPathExecute(
594 _ctx, "BoostedTreesCenterBias", name, tree_ensemble_handle,
595 mean_gradients, mean_hessians, l1, l2)
596 return _result
597 except _core._NotOkStatusException as e:
598 _ops.raise_from_not_ok_status(e, name)
599 except _core._FallbackException:
600 pass
601 try:
602 return boosted_trees_center_bias_eager_fallback(
603 tree_ensemble_handle, mean_gradients, mean_hessians, l1, l2,
604 name=name, ctx=_ctx)
605 except _core._SymbolicException:
606 pass # Add nodes to the TensorFlow graph.
607 # Add nodes to the TensorFlow graph.
608 _, _, _op, _outputs = _op_def_library._apply_op_helper(
609 "BoostedTreesCenterBias", tree_ensemble_handle=tree_ensemble_handle,
610 mean_gradients=mean_gradients,
611 mean_hessians=mean_hessians, l1=l1, l2=l2,
612 name=name)
613 _result = _outputs[:]
614 if _execute.must_record_gradient():
615 _attrs = ()
616 _inputs_flat = _op.inputs
617 _execute.record_gradient(
618 "BoostedTreesCenterBias", _inputs_flat, _attrs, _result)
619 _result, = _result
620 return _result
622BoostedTreesCenterBias = tf_export("raw_ops.BoostedTreesCenterBias")(_ops.to_raw_op(boosted_trees_center_bias))
625def boosted_trees_center_bias_eager_fallback(tree_ensemble_handle, mean_gradients, mean_hessians, l1, l2, name, ctx):
626 tree_ensemble_handle = _ops.convert_to_tensor(tree_ensemble_handle, _dtypes.resource)
627 mean_gradients = _ops.convert_to_tensor(mean_gradients, _dtypes.float32)
628 mean_hessians = _ops.convert_to_tensor(mean_hessians, _dtypes.float32)
629 l1 = _ops.convert_to_tensor(l1, _dtypes.float32)
630 l2 = _ops.convert_to_tensor(l2, _dtypes.float32)
631 _inputs_flat = [tree_ensemble_handle, mean_gradients, mean_hessians, l1, l2]
632 _attrs = None
633 _result = _execute.execute(b"BoostedTreesCenterBias", 1,
634 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
635 name=name)
636 if _execute.must_record_gradient():
637 _execute.record_gradient(
638 "BoostedTreesCenterBias", _inputs_flat, _attrs, _result)
639 _result, = _result
640 return _result
643def boosted_trees_create_ensemble(tree_ensemble_handle, stamp_token, tree_ensemble_serialized, name=None):
644 r"""Creates a tree ensemble model and returns a handle to it.
646 Args:
647 tree_ensemble_handle: A `Tensor` of type `resource`.
648 Handle to the tree ensemble resource to be created.
649 stamp_token: A `Tensor` of type `int64`.
650 Token to use as the initial value of the resource stamp.
651 tree_ensemble_serialized: A `Tensor` of type `string`.
652 Serialized proto of the tree ensemble.
653 name: A name for the operation (optional).
655 Returns:
656 The created Operation.
657 """
658 _ctx = _context._context or _context.context()
659 tld = _ctx._thread_local_data
660 if tld.is_eager:
661 try:
662 _result = pywrap_tfe.TFE_Py_FastPathExecute(
663 _ctx, "BoostedTreesCreateEnsemble", name, tree_ensemble_handle,
664 stamp_token, tree_ensemble_serialized)
665 return _result
666 except _core._NotOkStatusException as e:
667 _ops.raise_from_not_ok_status(e, name)
668 except _core._FallbackException:
669 pass
670 try:
671 return boosted_trees_create_ensemble_eager_fallback(
672 tree_ensemble_handle, stamp_token, tree_ensemble_serialized,
673 name=name, ctx=_ctx)
674 except _core._SymbolicException:
675 pass # Add nodes to the TensorFlow graph.
676 # Add nodes to the TensorFlow graph.
677 _, _, _op, _outputs = _op_def_library._apply_op_helper(
678 "BoostedTreesCreateEnsemble", tree_ensemble_handle=tree_ensemble_handle,
679 stamp_token=stamp_token,
680 tree_ensemble_serialized=tree_ensemble_serialized,
681 name=name)
682 return _op
683BoostedTreesCreateEnsemble = tf_export("raw_ops.BoostedTreesCreateEnsemble")(_ops.to_raw_op(boosted_trees_create_ensemble))
686def boosted_trees_create_ensemble_eager_fallback(tree_ensemble_handle, stamp_token, tree_ensemble_serialized, name, ctx):
687 tree_ensemble_handle = _ops.convert_to_tensor(tree_ensemble_handle, _dtypes.resource)
688 stamp_token = _ops.convert_to_tensor(stamp_token, _dtypes.int64)
689 tree_ensemble_serialized = _ops.convert_to_tensor(tree_ensemble_serialized, _dtypes.string)
690 _inputs_flat = [tree_ensemble_handle, stamp_token, tree_ensemble_serialized]
691 _attrs = None
692 _result = _execute.execute(b"BoostedTreesCreateEnsemble", 0,
693 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
694 name=name)
695 _result = None
696 return _result
699def boosted_trees_create_quantile_stream_resource(quantile_stream_resource_handle, epsilon, num_streams, max_elements=1099511627776, name=None):
700 r"""Create the Resource for Quantile Streams.
702 Args:
703 quantile_stream_resource_handle: A `Tensor` of type `resource`.
704 resource; Handle to quantile stream resource.
705 epsilon: A `Tensor` of type `float32`.
706 float; The required approximation error of the stream resource.
707 num_streams: A `Tensor` of type `int64`.
708 int; The number of streams managed by the resource that shares the same epsilon.
709 max_elements: An optional `int`. Defaults to `1099511627776`.
710 int; The maximum number of data points that can be fed to the stream.
711 name: A name for the operation (optional).
713 Returns:
714 The created Operation.
715 """
716 _ctx = _context._context or _context.context()
717 tld = _ctx._thread_local_data
718 if tld.is_eager:
719 try:
720 _result = pywrap_tfe.TFE_Py_FastPathExecute(
721 _ctx, "BoostedTreesCreateQuantileStreamResource", name,
722 quantile_stream_resource_handle, epsilon, num_streams, "max_elements",
723 max_elements)
724 return _result
725 except _core._NotOkStatusException as e:
726 _ops.raise_from_not_ok_status(e, name)
727 except _core._FallbackException:
728 pass
729 try:
730 return boosted_trees_create_quantile_stream_resource_eager_fallback(
731 quantile_stream_resource_handle, epsilon, num_streams,
732 max_elements=max_elements, name=name, ctx=_ctx)
733 except _core._SymbolicException:
734 pass # Add nodes to the TensorFlow graph.
735 # Add nodes to the TensorFlow graph.
736 if max_elements is None:
737 max_elements = 1099511627776
738 max_elements = _execute.make_int(max_elements, "max_elements")
739 _, _, _op, _outputs = _op_def_library._apply_op_helper(
740 "BoostedTreesCreateQuantileStreamResource", quantile_stream_resource_handle=quantile_stream_resource_handle,
741 epsilon=epsilon,
742 num_streams=num_streams,
743 max_elements=max_elements,
744 name=name)
745 return _op
746BoostedTreesCreateQuantileStreamResource = tf_export("raw_ops.BoostedTreesCreateQuantileStreamResource")(_ops.to_raw_op(boosted_trees_create_quantile_stream_resource))
749def boosted_trees_create_quantile_stream_resource_eager_fallback(quantile_stream_resource_handle, epsilon, num_streams, max_elements, name, ctx):
750 if max_elements is None:
751 max_elements = 1099511627776
752 max_elements = _execute.make_int(max_elements, "max_elements")
753 quantile_stream_resource_handle = _ops.convert_to_tensor(quantile_stream_resource_handle, _dtypes.resource)
754 epsilon = _ops.convert_to_tensor(epsilon, _dtypes.float32)
755 num_streams = _ops.convert_to_tensor(num_streams, _dtypes.int64)
756 _inputs_flat = [quantile_stream_resource_handle, epsilon, num_streams]
757 _attrs = ("max_elements", max_elements)
758 _result = _execute.execute(b"BoostedTreesCreateQuantileStreamResource", 0,
759 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
760 name=name)
761 _result = None
762 return _result
765def boosted_trees_deserialize_ensemble(tree_ensemble_handle, stamp_token, tree_ensemble_serialized, name=None):
766 r"""Deserializes a serialized tree ensemble config and replaces current tree
768 ensemble.
770 Args:
771 tree_ensemble_handle: A `Tensor` of type `resource`.
772 Handle to the tree ensemble.
773 stamp_token: A `Tensor` of type `int64`.
774 Token to use as the new value of the resource stamp.
775 tree_ensemble_serialized: A `Tensor` of type `string`.
776 Serialized proto of the ensemble.
777 name: A name for the operation (optional).
779 Returns:
780 The created Operation.
781 """
782 _ctx = _context._context or _context.context()
783 tld = _ctx._thread_local_data
784 if tld.is_eager:
785 try:
786 _result = pywrap_tfe.TFE_Py_FastPathExecute(
787 _ctx, "BoostedTreesDeserializeEnsemble", name, tree_ensemble_handle,
788 stamp_token, tree_ensemble_serialized)
789 return _result
790 except _core._NotOkStatusException as e:
791 _ops.raise_from_not_ok_status(e, name)
792 except _core._FallbackException:
793 pass
794 try:
795 return boosted_trees_deserialize_ensemble_eager_fallback(
796 tree_ensemble_handle, stamp_token, tree_ensemble_serialized,
797 name=name, ctx=_ctx)
798 except _core._SymbolicException:
799 pass # Add nodes to the TensorFlow graph.
800 # Add nodes to the TensorFlow graph.
801 _, _, _op, _outputs = _op_def_library._apply_op_helper(
802 "BoostedTreesDeserializeEnsemble", tree_ensemble_handle=tree_ensemble_handle,
803 stamp_token=stamp_token,
804 tree_ensemble_serialized=tree_ensemble_serialized,
805 name=name)
806 return _op
807BoostedTreesDeserializeEnsemble = tf_export("raw_ops.BoostedTreesDeserializeEnsemble")(_ops.to_raw_op(boosted_trees_deserialize_ensemble))
810def boosted_trees_deserialize_ensemble_eager_fallback(tree_ensemble_handle, stamp_token, tree_ensemble_serialized, name, ctx):
811 tree_ensemble_handle = _ops.convert_to_tensor(tree_ensemble_handle, _dtypes.resource)
812 stamp_token = _ops.convert_to_tensor(stamp_token, _dtypes.int64)
813 tree_ensemble_serialized = _ops.convert_to_tensor(tree_ensemble_serialized, _dtypes.string)
814 _inputs_flat = [tree_ensemble_handle, stamp_token, tree_ensemble_serialized]
815 _attrs = None
816 _result = _execute.execute(b"BoostedTreesDeserializeEnsemble", 0,
817 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
818 name=name)
819 _result = None
820 return _result
823def boosted_trees_ensemble_resource_handle_op(container="", shared_name="", name=None):
824 r"""Creates a handle to a BoostedTreesEnsembleResource
826 Args:
827 container: An optional `string`. Defaults to `""`.
828 shared_name: An optional `string`. Defaults to `""`.
829 name: A name for the operation (optional).
831 Returns:
832 A `Tensor` of type `resource`.
833 """
834 _ctx = _context._context or _context.context()
835 tld = _ctx._thread_local_data
836 if tld.is_eager:
837 try:
838 _result = pywrap_tfe.TFE_Py_FastPathExecute(
839 _ctx, "BoostedTreesEnsembleResourceHandleOp", name, "container",
840 container, "shared_name", shared_name)
841 return _result
842 except _core._NotOkStatusException as e:
843 _ops.raise_from_not_ok_status(e, name)
844 except _core._FallbackException:
845 pass
846 try:
847 return boosted_trees_ensemble_resource_handle_op_eager_fallback(
848 container=container, shared_name=shared_name, name=name, ctx=_ctx)
849 except _core._SymbolicException:
850 pass # Add nodes to the TensorFlow graph.
851 # Add nodes to the TensorFlow graph.
852 if container is None:
853 container = ""
854 container = _execute.make_str(container, "container")
855 if shared_name is None:
856 shared_name = ""
857 shared_name = _execute.make_str(shared_name, "shared_name")
858 _, _, _op, _outputs = _op_def_library._apply_op_helper(
859 "BoostedTreesEnsembleResourceHandleOp", container=container,
860 shared_name=shared_name,
861 name=name)
862 _result = _outputs[:]
863 if _execute.must_record_gradient():
864 _attrs = ("container", _op.get_attr("container"), "shared_name",
865 _op.get_attr("shared_name"))
866 _inputs_flat = _op.inputs
867 _execute.record_gradient(
868 "BoostedTreesEnsembleResourceHandleOp", _inputs_flat, _attrs, _result)
869 _result, = _result
870 return _result
872BoostedTreesEnsembleResourceHandleOp = tf_export("raw_ops.BoostedTreesEnsembleResourceHandleOp")(_ops.to_raw_op(boosted_trees_ensemble_resource_handle_op))
875def boosted_trees_ensemble_resource_handle_op_eager_fallback(container, shared_name, name, ctx):
876 if container is None:
877 container = ""
878 container = _execute.make_str(container, "container")
879 if shared_name is None:
880 shared_name = ""
881 shared_name = _execute.make_str(shared_name, "shared_name")
882 _inputs_flat = []
883 _attrs = ("container", container, "shared_name", shared_name)
884 _result = _execute.execute(b"BoostedTreesEnsembleResourceHandleOp", 1,
885 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
886 name=name)
887 if _execute.must_record_gradient():
888 _execute.record_gradient(
889 "BoostedTreesEnsembleResourceHandleOp", _inputs_flat, _attrs, _result)
890 _result, = _result
891 return _result
894def boosted_trees_example_debug_outputs(tree_ensemble_handle, bucketized_features, logits_dimension, name=None):
895 r"""Debugging/model interpretability outputs for each example.
897 It traverses all the trees and computes debug metrics for individual examples,
898 such as getting split feature ids and logits after each split along the decision
899 path used to compute directional feature contributions.
901 Args:
902 tree_ensemble_handle: A `Tensor` of type `resource`.
903 bucketized_features: A list of at least 1 `Tensor` objects with type `int32`.
904 A list of rank 1 Tensors containing bucket id for each
905 feature.
906 logits_dimension: An `int`.
907 scalar, dimension of the logits, to be used for constructing the protos in
908 examples_debug_outputs_serialized.
909 name: A name for the operation (optional).
911 Returns:
912 A `Tensor` of type `string`.
913 """
914 _ctx = _context._context or _context.context()
915 tld = _ctx._thread_local_data
916 if tld.is_eager:
917 try:
918 _result = pywrap_tfe.TFE_Py_FastPathExecute(
919 _ctx, "BoostedTreesExampleDebugOutputs", name, tree_ensemble_handle,
920 bucketized_features, "logits_dimension", logits_dimension)
921 return _result
922 except _core._NotOkStatusException as e:
923 _ops.raise_from_not_ok_status(e, name)
924 except _core._FallbackException:
925 pass
926 try:
927 return boosted_trees_example_debug_outputs_eager_fallback(
928 tree_ensemble_handle, bucketized_features,
929 logits_dimension=logits_dimension, name=name, ctx=_ctx)
930 except _core._SymbolicException:
931 pass # Add nodes to the TensorFlow graph.
932 # Add nodes to the TensorFlow graph.
933 if not isinstance(bucketized_features, (list, tuple)):
934 raise TypeError(
935 "Expected list for 'bucketized_features' argument to "
936 "'boosted_trees_example_debug_outputs' Op, not %r." % bucketized_features)
937 _attr_num_bucketized_features = len(bucketized_features)
938 logits_dimension = _execute.make_int(logits_dimension, "logits_dimension")
939 _, _, _op, _outputs = _op_def_library._apply_op_helper(
940 "BoostedTreesExampleDebugOutputs", tree_ensemble_handle=tree_ensemble_handle,
941 bucketized_features=bucketized_features,
942 logits_dimension=logits_dimension,
943 name=name)
944 _result = _outputs[:]
945 if _execute.must_record_gradient():
946 _attrs = ("num_bucketized_features",
947 _op._get_attr_int("num_bucketized_features"),
948 "logits_dimension", _op._get_attr_int("logits_dimension"))
949 _inputs_flat = _op.inputs
950 _execute.record_gradient(
951 "BoostedTreesExampleDebugOutputs", _inputs_flat, _attrs, _result)
952 _result, = _result
953 return _result
955BoostedTreesExampleDebugOutputs = tf_export("raw_ops.BoostedTreesExampleDebugOutputs")(_ops.to_raw_op(boosted_trees_example_debug_outputs))
958def boosted_trees_example_debug_outputs_eager_fallback(tree_ensemble_handle, bucketized_features, logits_dimension, name, ctx):
959 if not isinstance(bucketized_features, (list, tuple)):
960 raise TypeError(
961 "Expected list for 'bucketized_features' argument to "
962 "'boosted_trees_example_debug_outputs' Op, not %r." % bucketized_features)
963 _attr_num_bucketized_features = len(bucketized_features)
964 logits_dimension = _execute.make_int(logits_dimension, "logits_dimension")
965 tree_ensemble_handle = _ops.convert_to_tensor(tree_ensemble_handle, _dtypes.resource)
966 bucketized_features = _ops.convert_n_to_tensor(bucketized_features, _dtypes.int32)
967 _inputs_flat = [tree_ensemble_handle] + list(bucketized_features)
968 _attrs = ("num_bucketized_features", _attr_num_bucketized_features,
969 "logits_dimension", logits_dimension)
970 _result = _execute.execute(b"BoostedTreesExampleDebugOutputs", 1,
971 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
972 name=name)
973 if _execute.must_record_gradient():
974 _execute.record_gradient(
975 "BoostedTreesExampleDebugOutputs", _inputs_flat, _attrs, _result)
976 _result, = _result
977 return _result
980def boosted_trees_flush_quantile_summaries(quantile_stream_resource_handle, num_features, name=None):
981 r"""Flush the quantile summaries from each quantile stream resource.
983 An op that outputs a list of quantile summaries of a quantile stream resource.
984 Each summary Tensor is rank 2, containing summaries (value, weight, min_rank,
985 max_rank) for a single feature.
987 Args:
988 quantile_stream_resource_handle: A `Tensor` of type `resource`.
989 resource handle referring to a QuantileStreamResource.
990 num_features: An `int` that is `>= 0`.
991 name: A name for the operation (optional).
993 Returns:
994 A list of `num_features` `Tensor` objects with type `float32`.
995 """
996 _ctx = _context._context or _context.context()
997 tld = _ctx._thread_local_data
998 if tld.is_eager:
999 try:
1000 _result = pywrap_tfe.TFE_Py_FastPathExecute(
1001 _ctx, "BoostedTreesFlushQuantileSummaries", name,
1002 quantile_stream_resource_handle, "num_features", num_features)
1003 return _result
1004 except _core._NotOkStatusException as e:
1005 _ops.raise_from_not_ok_status(e, name)
1006 except _core._FallbackException:
1007 pass
1008 try:
1009 return boosted_trees_flush_quantile_summaries_eager_fallback(
1010 quantile_stream_resource_handle, num_features=num_features,
1011 name=name, ctx=_ctx)
1012 except _core._SymbolicException:
1013 pass # Add nodes to the TensorFlow graph.
1014 # Add nodes to the TensorFlow graph.
1015 num_features = _execute.make_int(num_features, "num_features")
1016 _, _, _op, _outputs = _op_def_library._apply_op_helper(
1017 "BoostedTreesFlushQuantileSummaries", quantile_stream_resource_handle=quantile_stream_resource_handle,
1018 num_features=num_features,
1019 name=name)
1020 _result = _outputs[:]
1021 if not _result:
1022 return _op
1023 if _execute.must_record_gradient():
1024 _attrs = ("num_features", _op._get_attr_int("num_features"))
1025 _inputs_flat = _op.inputs
1026 _execute.record_gradient(
1027 "BoostedTreesFlushQuantileSummaries", _inputs_flat, _attrs, _result)
1028 return _result
1030BoostedTreesFlushQuantileSummaries = tf_export("raw_ops.BoostedTreesFlushQuantileSummaries")(_ops.to_raw_op(boosted_trees_flush_quantile_summaries))
1033def boosted_trees_flush_quantile_summaries_eager_fallback(quantile_stream_resource_handle, num_features, name, ctx):
1034 num_features = _execute.make_int(num_features, "num_features")
1035 quantile_stream_resource_handle = _ops.convert_to_tensor(quantile_stream_resource_handle, _dtypes.resource)
1036 _inputs_flat = [quantile_stream_resource_handle]
1037 _attrs = ("num_features", num_features)
1038 _result = _execute.execute(b"BoostedTreesFlushQuantileSummaries",
1039 num_features, inputs=_inputs_flat, attrs=_attrs,
1040 ctx=ctx, name=name)
1041 if _execute.must_record_gradient():
1042 _execute.record_gradient(
1043 "BoostedTreesFlushQuantileSummaries", _inputs_flat, _attrs, _result)
1044 return _result
1046_BoostedTreesGetEnsembleStatesOutput = collections.namedtuple(
1047 "BoostedTreesGetEnsembleStates",
1048 ["stamp_token", "num_trees", "num_finalized_trees", "num_attempted_layers", "last_layer_nodes_range"])
1051def boosted_trees_get_ensemble_states(tree_ensemble_handle, name=None):
1052 r"""Retrieves the tree ensemble resource stamp token, number of trees and growing statistics.
1054 Args:
1055 tree_ensemble_handle: A `Tensor` of type `resource`.
1056 Handle to the tree ensemble.
1057 name: A name for the operation (optional).
1059 Returns:
1060 A tuple of `Tensor` objects (stamp_token, num_trees, num_finalized_trees, num_attempted_layers, last_layer_nodes_range).
1062 stamp_token: A `Tensor` of type `int64`.
1063 num_trees: A `Tensor` of type `int32`.
1064 num_finalized_trees: A `Tensor` of type `int32`.
1065 num_attempted_layers: A `Tensor` of type `int32`.
1066 last_layer_nodes_range: A `Tensor` of type `int32`.
1067 """
1068 _ctx = _context._context or _context.context()
1069 tld = _ctx._thread_local_data
1070 if tld.is_eager:
1071 try:
1072 _result = pywrap_tfe.TFE_Py_FastPathExecute(
1073 _ctx, "BoostedTreesGetEnsembleStates", name, tree_ensemble_handle)
1074 _result = _BoostedTreesGetEnsembleStatesOutput._make(_result)
1075 return _result
1076 except _core._NotOkStatusException as e:
1077 _ops.raise_from_not_ok_status(e, name)
1078 except _core._FallbackException:
1079 pass
1080 try:
1081 return boosted_trees_get_ensemble_states_eager_fallback(
1082 tree_ensemble_handle, name=name, ctx=_ctx)
1083 except _core._SymbolicException:
1084 pass # Add nodes to the TensorFlow graph.
1085 # Add nodes to the TensorFlow graph.
1086 _, _, _op, _outputs = _op_def_library._apply_op_helper(
1087 "BoostedTreesGetEnsembleStates", tree_ensemble_handle=tree_ensemble_handle,
1088 name=name)
1089 _result = _outputs[:]
1090 if _execute.must_record_gradient():
1091 _attrs = ()
1092 _inputs_flat = _op.inputs
1093 _execute.record_gradient(
1094 "BoostedTreesGetEnsembleStates", _inputs_flat, _attrs, _result)
1095 _result = _BoostedTreesGetEnsembleStatesOutput._make(_result)
1096 return _result
1098BoostedTreesGetEnsembleStates = tf_export("raw_ops.BoostedTreesGetEnsembleStates")(_ops.to_raw_op(boosted_trees_get_ensemble_states))
1101def boosted_trees_get_ensemble_states_eager_fallback(tree_ensemble_handle, name, ctx):
1102 tree_ensemble_handle = _ops.convert_to_tensor(tree_ensemble_handle, _dtypes.resource)
1103 _inputs_flat = [tree_ensemble_handle]
1104 _attrs = None
1105 _result = _execute.execute(b"BoostedTreesGetEnsembleStates", 5,
1106 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
1107 name=name)
1108 if _execute.must_record_gradient():
1109 _execute.record_gradient(
1110 "BoostedTreesGetEnsembleStates", _inputs_flat, _attrs, _result)
1111 _result = _BoostedTreesGetEnsembleStatesOutput._make(_result)
1112 return _result
1115def boosted_trees_make_quantile_summaries(float_values, example_weights, epsilon, name=None):
1116 r"""Makes the summary of quantiles for the batch.
1118 An op that takes a list of tensors (one tensor per feature) and outputs the
1119 quantile summaries for each tensor.
1121 Args:
1122 float_values: A list of `Tensor` objects with type `float32`.
1123 float; List of Rank 1 Tensors each containing values for a single feature.
1124 example_weights: A `Tensor` of type `float32`.
1125 float; Rank 1 Tensor with weights per instance.
1126 epsilon: A `Tensor` of type `float32`.
1127 float; The required maximum approximation error.
1128 name: A name for the operation (optional).
1130 Returns:
1131 A list with the same length as `float_values` of `Tensor` objects with type `float32`.
1132 """
1133 _ctx = _context._context or _context.context()
1134 tld = _ctx._thread_local_data
1135 if tld.is_eager:
1136 try:
1137 _result = pywrap_tfe.TFE_Py_FastPathExecute(
1138 _ctx, "BoostedTreesMakeQuantileSummaries", name, float_values,
1139 example_weights, epsilon)
1140 return _result
1141 except _core._NotOkStatusException as e:
1142 _ops.raise_from_not_ok_status(e, name)
1143 except _core._FallbackException:
1144 pass
1145 try:
1146 return boosted_trees_make_quantile_summaries_eager_fallback(
1147 float_values, example_weights, epsilon, name=name, ctx=_ctx)
1148 except _core._SymbolicException:
1149 pass # Add nodes to the TensorFlow graph.
1150 # Add nodes to the TensorFlow graph.
1151 if not isinstance(float_values, (list, tuple)):
1152 raise TypeError(
1153 "Expected list for 'float_values' argument to "
1154 "'boosted_trees_make_quantile_summaries' Op, not %r." % float_values)
1155 _attr_num_features = len(float_values)
1156 _, _, _op, _outputs = _op_def_library._apply_op_helper(
1157 "BoostedTreesMakeQuantileSummaries", float_values=float_values,
1158 example_weights=example_weights,
1159 epsilon=epsilon, name=name)
1160 _result = _outputs[:]
1161 if _execute.must_record_gradient():
1162 _attrs = ("num_features", _op._get_attr_int("num_features"))
1163 _inputs_flat = _op.inputs
1164 _execute.record_gradient(
1165 "BoostedTreesMakeQuantileSummaries", _inputs_flat, _attrs, _result)
1166 return _result
1168BoostedTreesMakeQuantileSummaries = tf_export("raw_ops.BoostedTreesMakeQuantileSummaries")(_ops.to_raw_op(boosted_trees_make_quantile_summaries))
1171def boosted_trees_make_quantile_summaries_eager_fallback(float_values, example_weights, epsilon, name, ctx):
1172 if not isinstance(float_values, (list, tuple)):
1173 raise TypeError(
1174 "Expected list for 'float_values' argument to "
1175 "'boosted_trees_make_quantile_summaries' Op, not %r." % float_values)
1176 _attr_num_features = len(float_values)
1177 float_values = _ops.convert_n_to_tensor(float_values, _dtypes.float32)
1178 example_weights = _ops.convert_to_tensor(example_weights, _dtypes.float32)
1179 epsilon = _ops.convert_to_tensor(epsilon, _dtypes.float32)
1180 _inputs_flat = list(float_values) + [example_weights, epsilon]
1181 _attrs = ("num_features", _attr_num_features)
1182 _result = _execute.execute(b"BoostedTreesMakeQuantileSummaries",
1183 _attr_num_features, inputs=_inputs_flat,
1184 attrs=_attrs, ctx=ctx, name=name)
1185 if _execute.must_record_gradient():
1186 _execute.record_gradient(
1187 "BoostedTreesMakeQuantileSummaries", _inputs_flat, _attrs, _result)
1188 return _result
1191def boosted_trees_make_stats_summary(node_ids, gradients, hessians, bucketized_features_list, max_splits, num_buckets, name=None):
1192 r"""Makes the summary of accumulated stats for the batch.
1194 The summary stats contains gradients and hessians accumulated into the corresponding node and bucket for each example.
1196 Args:
1197 node_ids: A `Tensor` of type `int32`.
1198 int32 Rank 1 Tensor containing node ids, which each example falls into for the requested layer.
1199 gradients: A `Tensor` of type `float32`.
1200 float32; Rank 2 Tensor (shape=[#examples, 1]) for gradients.
1201 hessians: A `Tensor` of type `float32`.
1202 float32; Rank 2 Tensor (shape=[#examples, 1]) for hessians.
1203 bucketized_features_list: A list of at least 1 `Tensor` objects with type `int32`.
1204 int32 list of Rank 1 Tensors, each containing the bucketized feature (for each feature column).
1205 max_splits: An `int` that is `>= 1`.
1206 int; the maximum number of splits possible in the whole tree.
1207 num_buckets: An `int` that is `>= 1`.
1208 int; equals to the maximum possible value of bucketized feature.
1209 name: A name for the operation (optional).
1211 Returns:
1212 A `Tensor` of type `float32`.
1213 """
1214 _ctx = _context._context or _context.context()
1215 tld = _ctx._thread_local_data
1216 if tld.is_eager:
1217 try:
1218 _result = pywrap_tfe.TFE_Py_FastPathExecute(
1219 _ctx, "BoostedTreesMakeStatsSummary", name, node_ids, gradients,
1220 hessians, bucketized_features_list, "max_splits", max_splits,
1221 "num_buckets", num_buckets)
1222 return _result
1223 except _core._NotOkStatusException as e:
1224 _ops.raise_from_not_ok_status(e, name)
1225 except _core._FallbackException:
1226 pass
1227 try:
1228 return boosted_trees_make_stats_summary_eager_fallback(
1229 node_ids, gradients, hessians, bucketized_features_list,
1230 max_splits=max_splits, num_buckets=num_buckets, name=name, ctx=_ctx)
1231 except _core._SymbolicException:
1232 pass # Add nodes to the TensorFlow graph.
1233 # Add nodes to the TensorFlow graph.
1234 if not isinstance(bucketized_features_list, (list, tuple)):
1235 raise TypeError(
1236 "Expected list for 'bucketized_features_list' argument to "
1237 "'boosted_trees_make_stats_summary' Op, not %r." % bucketized_features_list)
1238 _attr_num_features = len(bucketized_features_list)
1239 max_splits = _execute.make_int(max_splits, "max_splits")
1240 num_buckets = _execute.make_int(num_buckets, "num_buckets")
1241 _, _, _op, _outputs = _op_def_library._apply_op_helper(
1242 "BoostedTreesMakeStatsSummary", node_ids=node_ids,
1243 gradients=gradients,
1244 hessians=hessians,
1245 bucketized_features_list=bucketized_features_list,
1246 max_splits=max_splits,
1247 num_buckets=num_buckets, name=name)
1248 _result = _outputs[:]
1249 if _execute.must_record_gradient():
1250 _attrs = ("max_splits", _op._get_attr_int("max_splits"), "num_buckets",
1251 _op._get_attr_int("num_buckets"), "num_features",
1252 _op._get_attr_int("num_features"))
1253 _inputs_flat = _op.inputs
1254 _execute.record_gradient(
1255 "BoostedTreesMakeStatsSummary", _inputs_flat, _attrs, _result)
1256 _result, = _result
1257 return _result
1259BoostedTreesMakeStatsSummary = tf_export("raw_ops.BoostedTreesMakeStatsSummary")(_ops.to_raw_op(boosted_trees_make_stats_summary))
1262def boosted_trees_make_stats_summary_eager_fallback(node_ids, gradients, hessians, bucketized_features_list, max_splits, num_buckets, name, ctx):
1263 if not isinstance(bucketized_features_list, (list, tuple)):
1264 raise TypeError(
1265 "Expected list for 'bucketized_features_list' argument to "
1266 "'boosted_trees_make_stats_summary' Op, not %r." % bucketized_features_list)
1267 _attr_num_features = len(bucketized_features_list)
1268 max_splits = _execute.make_int(max_splits, "max_splits")
1269 num_buckets = _execute.make_int(num_buckets, "num_buckets")
1270 node_ids = _ops.convert_to_tensor(node_ids, _dtypes.int32)
1271 gradients = _ops.convert_to_tensor(gradients, _dtypes.float32)
1272 hessians = _ops.convert_to_tensor(hessians, _dtypes.float32)
1273 bucketized_features_list = _ops.convert_n_to_tensor(bucketized_features_list, _dtypes.int32)
1274 _inputs_flat = [node_ids, gradients, hessians] + list(bucketized_features_list)
1275 _attrs = ("max_splits", max_splits, "num_buckets", num_buckets,
1276 "num_features", _attr_num_features)
1277 _result = _execute.execute(b"BoostedTreesMakeStatsSummary", 1,
1278 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
1279 name=name)
1280 if _execute.must_record_gradient():
1281 _execute.record_gradient(
1282 "BoostedTreesMakeStatsSummary", _inputs_flat, _attrs, _result)
1283 _result, = _result
1284 return _result
1287def boosted_trees_predict(tree_ensemble_handle, bucketized_features, logits_dimension, name=None):
1288 r"""Runs multiple additive regression ensemble predictors on input instances and
1290 computes the logits. It is designed to be used during prediction.
1291 It traverses all the trees and calculates the final score for each instance.
1293 Args:
1294 tree_ensemble_handle: A `Tensor` of type `resource`.
1295 bucketized_features: A list of at least 1 `Tensor` objects with type `int32`.
1296 A list of rank 1 Tensors containing bucket id for each
1297 feature.
1298 logits_dimension: An `int`.
1299 scalar, dimension of the logits, to be used for partial logits
1300 shape.
1301 name: A name for the operation (optional).
1303 Returns:
1304 A `Tensor` of type `float32`.
1305 """
1306 _ctx = _context._context or _context.context()
1307 tld = _ctx._thread_local_data
1308 if tld.is_eager:
1309 try:
1310 _result = pywrap_tfe.TFE_Py_FastPathExecute(
1311 _ctx, "BoostedTreesPredict", name, tree_ensemble_handle,
1312 bucketized_features, "logits_dimension", logits_dimension)
1313 return _result
1314 except _core._NotOkStatusException as e:
1315 _ops.raise_from_not_ok_status(e, name)
1316 except _core._FallbackException:
1317 pass
1318 try:
1319 return boosted_trees_predict_eager_fallback(
1320 tree_ensemble_handle, bucketized_features,
1321 logits_dimension=logits_dimension, name=name, ctx=_ctx)
1322 except _core._SymbolicException:
1323 pass # Add nodes to the TensorFlow graph.
1324 # Add nodes to the TensorFlow graph.
1325 if not isinstance(bucketized_features, (list, tuple)):
1326 raise TypeError(
1327 "Expected list for 'bucketized_features' argument to "
1328 "'boosted_trees_predict' Op, not %r." % bucketized_features)
1329 _attr_num_bucketized_features = len(bucketized_features)
1330 logits_dimension = _execute.make_int(logits_dimension, "logits_dimension")
1331 _, _, _op, _outputs = _op_def_library._apply_op_helper(
1332 "BoostedTreesPredict", tree_ensemble_handle=tree_ensemble_handle,
1333 bucketized_features=bucketized_features,
1334 logits_dimension=logits_dimension, name=name)
1335 _result = _outputs[:]
1336 if _execute.must_record_gradient():
1337 _attrs = ("num_bucketized_features",
1338 _op._get_attr_int("num_bucketized_features"),
1339 "logits_dimension", _op._get_attr_int("logits_dimension"))
1340 _inputs_flat = _op.inputs
1341 _execute.record_gradient(
1342 "BoostedTreesPredict", _inputs_flat, _attrs, _result)
1343 _result, = _result
1344 return _result
1346BoostedTreesPredict = tf_export("raw_ops.BoostedTreesPredict")(_ops.to_raw_op(boosted_trees_predict))
1349def boosted_trees_predict_eager_fallback(tree_ensemble_handle, bucketized_features, logits_dimension, name, ctx):
1350 if not isinstance(bucketized_features, (list, tuple)):
1351 raise TypeError(
1352 "Expected list for 'bucketized_features' argument to "
1353 "'boosted_trees_predict' Op, not %r." % bucketized_features)
1354 _attr_num_bucketized_features = len(bucketized_features)
1355 logits_dimension = _execute.make_int(logits_dimension, "logits_dimension")
1356 tree_ensemble_handle = _ops.convert_to_tensor(tree_ensemble_handle, _dtypes.resource)
1357 bucketized_features = _ops.convert_n_to_tensor(bucketized_features, _dtypes.int32)
1358 _inputs_flat = [tree_ensemble_handle] + list(bucketized_features)
1359 _attrs = ("num_bucketized_features", _attr_num_bucketized_features,
1360 "logits_dimension", logits_dimension)
1361 _result = _execute.execute(b"BoostedTreesPredict", 1, inputs=_inputs_flat,
1362 attrs=_attrs, ctx=ctx, name=name)
1363 if _execute.must_record_gradient():
1364 _execute.record_gradient(
1365 "BoostedTreesPredict", _inputs_flat, _attrs, _result)
1366 _result, = _result
1367 return _result
1370def boosted_trees_quantile_stream_resource_add_summaries(quantile_stream_resource_handle, summaries, name=None):
1371 r"""Add the quantile summaries to each quantile stream resource.
1373 An op that adds a list of quantile summaries to a quantile stream resource. Each
1374 summary Tensor is rank 2, containing summaries (value, weight, min_rank, max_rank)
1375 for a single feature.
1377 Args:
1378 quantile_stream_resource_handle: A `Tensor` of type `resource`.
1379 resource handle referring to a QuantileStreamResource.
1380 summaries: A list of `Tensor` objects with type `float32`.
1381 string; List of Rank 2 Tensor each containing the summaries for a single feature.
1382 name: A name for the operation (optional).
1384 Returns:
1385 The created Operation.
1386 """
1387 _ctx = _context._context or _context.context()
1388 tld = _ctx._thread_local_data
1389 if tld.is_eager:
1390 try:
1391 _result = pywrap_tfe.TFE_Py_FastPathExecute(
1392 _ctx, "BoostedTreesQuantileStreamResourceAddSummaries", name,
1393 quantile_stream_resource_handle, summaries)
1394 return _result
1395 except _core._NotOkStatusException as e:
1396 _ops.raise_from_not_ok_status(e, name)
1397 except _core._FallbackException:
1398 pass
1399 try:
1400 return boosted_trees_quantile_stream_resource_add_summaries_eager_fallback(
1401 quantile_stream_resource_handle, summaries, name=name, ctx=_ctx)
1402 except _core._SymbolicException:
1403 pass # Add nodes to the TensorFlow graph.
1404 # Add nodes to the TensorFlow graph.
1405 if not isinstance(summaries, (list, tuple)):
1406 raise TypeError(
1407 "Expected list for 'summaries' argument to "
1408 "'boosted_trees_quantile_stream_resource_add_summaries' Op, not %r." % summaries)
1409 _attr_num_features = len(summaries)
1410 _, _, _op, _outputs = _op_def_library._apply_op_helper(
1411 "BoostedTreesQuantileStreamResourceAddSummaries", quantile_stream_resource_handle=quantile_stream_resource_handle,
1412 summaries=summaries,
1413 name=name)
1414 return _op
1415BoostedTreesQuantileStreamResourceAddSummaries = tf_export("raw_ops.BoostedTreesQuantileStreamResourceAddSummaries")(_ops.to_raw_op(boosted_trees_quantile_stream_resource_add_summaries))
1418def boosted_trees_quantile_stream_resource_add_summaries_eager_fallback(quantile_stream_resource_handle, summaries, name, ctx):
1419 if not isinstance(summaries, (list, tuple)):
1420 raise TypeError(
1421 "Expected list for 'summaries' argument to "
1422 "'boosted_trees_quantile_stream_resource_add_summaries' Op, not %r." % summaries)
1423 _attr_num_features = len(summaries)
1424 quantile_stream_resource_handle = _ops.convert_to_tensor(quantile_stream_resource_handle, _dtypes.resource)
1425 summaries = _ops.convert_n_to_tensor(summaries, _dtypes.float32)
1426 _inputs_flat = [quantile_stream_resource_handle] + list(summaries)
1427 _attrs = ("num_features", _attr_num_features)
1428 _result = _execute.execute(b"BoostedTreesQuantileStreamResourceAddSummaries",
1429 0, inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
1430 name=name)
1431 _result = None
1432 return _result
1435def boosted_trees_quantile_stream_resource_deserialize(quantile_stream_resource_handle, bucket_boundaries, name=None):
1436 r"""Deserialize bucket boundaries and ready flag into current QuantileAccumulator.
1438 An op that deserializes bucket boundaries and are boundaries ready flag into current QuantileAccumulator.
1440 Args:
1441 quantile_stream_resource_handle: A `Tensor` of type `resource`.
1442 resource handle referring to a QuantileStreamResource.
1443 bucket_boundaries: A list of at least 1 `Tensor` objects with type `float32`.
1444 float; List of Rank 1 Tensors each containing the bucket boundaries for a feature.
1445 name: A name for the operation (optional).
1447 Returns:
1448 The created Operation.
1449 """
1450 _ctx = _context._context or _context.context()
1451 tld = _ctx._thread_local_data
1452 if tld.is_eager:
1453 try:
1454 _result = pywrap_tfe.TFE_Py_FastPathExecute(
1455 _ctx, "BoostedTreesQuantileStreamResourceDeserialize", name,
1456 quantile_stream_resource_handle, bucket_boundaries)
1457 return _result
1458 except _core._NotOkStatusException as e:
1459 _ops.raise_from_not_ok_status(e, name)
1460 except _core._FallbackException:
1461 pass
1462 try:
1463 return boosted_trees_quantile_stream_resource_deserialize_eager_fallback(
1464 quantile_stream_resource_handle, bucket_boundaries, name=name,
1465 ctx=_ctx)
1466 except _core._SymbolicException:
1467 pass # Add nodes to the TensorFlow graph.
1468 # Add nodes to the TensorFlow graph.
1469 if not isinstance(bucket_boundaries, (list, tuple)):
1470 raise TypeError(
1471 "Expected list for 'bucket_boundaries' argument to "
1472 "'boosted_trees_quantile_stream_resource_deserialize' Op, not %r." % bucket_boundaries)
1473 _attr_num_streams = len(bucket_boundaries)
1474 _, _, _op, _outputs = _op_def_library._apply_op_helper(
1475 "BoostedTreesQuantileStreamResourceDeserialize", quantile_stream_resource_handle=quantile_stream_resource_handle,
1476 bucket_boundaries=bucket_boundaries,
1477 name=name)
1478 return _op
1479BoostedTreesQuantileStreamResourceDeserialize = tf_export("raw_ops.BoostedTreesQuantileStreamResourceDeserialize")(_ops.to_raw_op(boosted_trees_quantile_stream_resource_deserialize))
1482def boosted_trees_quantile_stream_resource_deserialize_eager_fallback(quantile_stream_resource_handle, bucket_boundaries, name, ctx):
1483 if not isinstance(bucket_boundaries, (list, tuple)):
1484 raise TypeError(
1485 "Expected list for 'bucket_boundaries' argument to "
1486 "'boosted_trees_quantile_stream_resource_deserialize' Op, not %r." % bucket_boundaries)
1487 _attr_num_streams = len(bucket_boundaries)
1488 quantile_stream_resource_handle = _ops.convert_to_tensor(quantile_stream_resource_handle, _dtypes.resource)
1489 bucket_boundaries = _ops.convert_n_to_tensor(bucket_boundaries, _dtypes.float32)
1490 _inputs_flat = [quantile_stream_resource_handle] + list(bucket_boundaries)
1491 _attrs = ("num_streams", _attr_num_streams)
1492 _result = _execute.execute(b"BoostedTreesQuantileStreamResourceDeserialize",
1493 0, inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
1494 name=name)
1495 _result = None
1496 return _result
1499def boosted_trees_quantile_stream_resource_flush(quantile_stream_resource_handle, num_buckets, generate_quantiles=False, name=None):
1500 r"""Flush the summaries for a quantile stream resource.
1502 An op that flushes the summaries for a quantile stream resource.
1504 Args:
1505 quantile_stream_resource_handle: A `Tensor` of type `resource`.
1506 resource handle referring to a QuantileStreamResource.
1507 num_buckets: A `Tensor` of type `int64`.
1508 int; approximate number of buckets unless using generate_quantiles.
1509 generate_quantiles: An optional `bool`. Defaults to `False`.
1510 bool; If True, the output will be the num_quantiles for each stream where the ith
1511 entry is the ith quantile of the input with an approximation error of epsilon.
1512 Duplicate values may be present.
1513 If False, the output will be the points in the histogram that we got which roughly
1514 translates to 1/epsilon boundaries and without any duplicates.
1515 Default to False.
1516 name: A name for the operation (optional).
1518 Returns:
1519 The created Operation.
1520 """
1521 _ctx = _context._context or _context.context()
1522 tld = _ctx._thread_local_data
1523 if tld.is_eager:
1524 try:
1525 _result = pywrap_tfe.TFE_Py_FastPathExecute(
1526 _ctx, "BoostedTreesQuantileStreamResourceFlush", name,
1527 quantile_stream_resource_handle, num_buckets, "generate_quantiles",
1528 generate_quantiles)
1529 return _result
1530 except _core._NotOkStatusException as e:
1531 _ops.raise_from_not_ok_status(e, name)
1532 except _core._FallbackException:
1533 pass
1534 try:
1535 return boosted_trees_quantile_stream_resource_flush_eager_fallback(
1536 quantile_stream_resource_handle, num_buckets,
1537 generate_quantiles=generate_quantiles, name=name, ctx=_ctx)
1538 except _core._SymbolicException:
1539 pass # Add nodes to the TensorFlow graph.
1540 # Add nodes to the TensorFlow graph.
1541 if generate_quantiles is None:
1542 generate_quantiles = False
1543 generate_quantiles = _execute.make_bool(generate_quantiles, "generate_quantiles")
1544 _, _, _op, _outputs = _op_def_library._apply_op_helper(
1545 "BoostedTreesQuantileStreamResourceFlush", quantile_stream_resource_handle=quantile_stream_resource_handle,
1546 num_buckets=num_buckets,
1547 generate_quantiles=generate_quantiles,
1548 name=name)
1549 return _op
1550BoostedTreesQuantileStreamResourceFlush = tf_export("raw_ops.BoostedTreesQuantileStreamResourceFlush")(_ops.to_raw_op(boosted_trees_quantile_stream_resource_flush))
1553def boosted_trees_quantile_stream_resource_flush_eager_fallback(quantile_stream_resource_handle, num_buckets, generate_quantiles, name, ctx):
1554 if generate_quantiles is None:
1555 generate_quantiles = False
1556 generate_quantiles = _execute.make_bool(generate_quantiles, "generate_quantiles")
1557 quantile_stream_resource_handle = _ops.convert_to_tensor(quantile_stream_resource_handle, _dtypes.resource)
1558 num_buckets = _ops.convert_to_tensor(num_buckets, _dtypes.int64)
1559 _inputs_flat = [quantile_stream_resource_handle, num_buckets]
1560 _attrs = ("generate_quantiles", generate_quantiles)
1561 _result = _execute.execute(b"BoostedTreesQuantileStreamResourceFlush", 0,
1562 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
1563 name=name)
1564 _result = None
1565 return _result
1568def boosted_trees_quantile_stream_resource_get_bucket_boundaries(quantile_stream_resource_handle, num_features, name=None):
1569 r"""Generate the bucket boundaries for each feature based on accumulated summaries.
1571 An op that returns a list of float tensors for a quantile stream resource. Each
1572 tensor is Rank 1 containing bucket boundaries for a single feature.
1574 Args:
1575 quantile_stream_resource_handle: A `Tensor` of type `resource`.
1576 resource handle referring to a QuantileStreamResource.
1577 num_features: An `int` that is `>= 0`.
1578 inferred int; number of features to get bucket boundaries for.
1579 name: A name for the operation (optional).
1581 Returns:
1582 A list of `num_features` `Tensor` objects with type `float32`.
1583 """
1584 _ctx = _context._context or _context.context()
1585 tld = _ctx._thread_local_data
1586 if tld.is_eager:
1587 try:
1588 _result = pywrap_tfe.TFE_Py_FastPathExecute(
1589 _ctx, "BoostedTreesQuantileStreamResourceGetBucketBoundaries", name,
1590 quantile_stream_resource_handle, "num_features", num_features)
1591 return _result
1592 except _core._NotOkStatusException as e:
1593 _ops.raise_from_not_ok_status(e, name)
1594 except _core._FallbackException:
1595 pass
1596 try:
1597 return boosted_trees_quantile_stream_resource_get_bucket_boundaries_eager_fallback(
1598 quantile_stream_resource_handle, num_features=num_features,
1599 name=name, ctx=_ctx)
1600 except _core._SymbolicException:
1601 pass # Add nodes to the TensorFlow graph.
1602 # Add nodes to the TensorFlow graph.
1603 num_features = _execute.make_int(num_features, "num_features")
1604 _, _, _op, _outputs = _op_def_library._apply_op_helper(
1605 "BoostedTreesQuantileStreamResourceGetBucketBoundaries", quantile_stream_resource_handle=quantile_stream_resource_handle,
1606 num_features=num_features,
1607 name=name)
1608 _result = _outputs[:]
1609 if not _result:
1610 return _op
1611 if _execute.must_record_gradient():
1612 _attrs = ("num_features", _op._get_attr_int("num_features"))
1613 _inputs_flat = _op.inputs
1614 _execute.record_gradient(
1615 "BoostedTreesQuantileStreamResourceGetBucketBoundaries", _inputs_flat, _attrs, _result)
1616 return _result
1618BoostedTreesQuantileStreamResourceGetBucketBoundaries = tf_export("raw_ops.BoostedTreesQuantileStreamResourceGetBucketBoundaries")(_ops.to_raw_op(boosted_trees_quantile_stream_resource_get_bucket_boundaries))
1621def boosted_trees_quantile_stream_resource_get_bucket_boundaries_eager_fallback(quantile_stream_resource_handle, num_features, name, ctx):
1622 num_features = _execute.make_int(num_features, "num_features")
1623 quantile_stream_resource_handle = _ops.convert_to_tensor(quantile_stream_resource_handle, _dtypes.resource)
1624 _inputs_flat = [quantile_stream_resource_handle]
1625 _attrs = ("num_features", num_features)
1626 _result = _execute.execute(b"BoostedTreesQuantileStreamResourceGetBucketBoundaries",
1627 num_features, inputs=_inputs_flat, attrs=_attrs,
1628 ctx=ctx, name=name)
1629 if _execute.must_record_gradient():
1630 _execute.record_gradient(
1631 "BoostedTreesQuantileStreamResourceGetBucketBoundaries", _inputs_flat, _attrs, _result)
1632 return _result
1635def boosted_trees_quantile_stream_resource_handle_op(container="", shared_name="", name=None):
1636 r"""Creates a handle to a BoostedTreesQuantileStreamResource.
1638 Args:
1639 container: An optional `string`. Defaults to `""`.
1640 shared_name: An optional `string`. Defaults to `""`.
1641 name: A name for the operation (optional).
1643 Returns:
1644 A `Tensor` of type `resource`.
1645 """
1646 _ctx = _context._context or _context.context()
1647 tld = _ctx._thread_local_data
1648 if tld.is_eager:
1649 try:
1650 _result = pywrap_tfe.TFE_Py_FastPathExecute(
1651 _ctx, "BoostedTreesQuantileStreamResourceHandleOp", name, "container",
1652 container, "shared_name", shared_name)
1653 return _result
1654 except _core._NotOkStatusException as e:
1655 _ops.raise_from_not_ok_status(e, name)
1656 except _core._FallbackException:
1657 pass
1658 try:
1659 return boosted_trees_quantile_stream_resource_handle_op_eager_fallback(
1660 container=container, shared_name=shared_name, name=name, ctx=_ctx)
1661 except _core._SymbolicException:
1662 pass # Add nodes to the TensorFlow graph.
1663 # Add nodes to the TensorFlow graph.
1664 if container is None:
1665 container = ""
1666 container = _execute.make_str(container, "container")
1667 if shared_name is None:
1668 shared_name = ""
1669 shared_name = _execute.make_str(shared_name, "shared_name")
1670 _, _, _op, _outputs = _op_def_library._apply_op_helper(
1671 "BoostedTreesQuantileStreamResourceHandleOp", container=container,
1672 shared_name=shared_name,
1673 name=name)
1674 _result = _outputs[:]
1675 if _execute.must_record_gradient():
1676 _attrs = ("container", _op.get_attr("container"), "shared_name",
1677 _op.get_attr("shared_name"))
1678 _inputs_flat = _op.inputs
1679 _execute.record_gradient(
1680 "BoostedTreesQuantileStreamResourceHandleOp", _inputs_flat, _attrs, _result)
1681 _result, = _result
1682 return _result
1684BoostedTreesQuantileStreamResourceHandleOp = tf_export("raw_ops.BoostedTreesQuantileStreamResourceHandleOp")(_ops.to_raw_op(boosted_trees_quantile_stream_resource_handle_op))
1687def boosted_trees_quantile_stream_resource_handle_op_eager_fallback(container, shared_name, name, ctx):
1688 if container is None:
1689 container = ""
1690 container = _execute.make_str(container, "container")
1691 if shared_name is None:
1692 shared_name = ""
1693 shared_name = _execute.make_str(shared_name, "shared_name")
1694 _inputs_flat = []
1695 _attrs = ("container", container, "shared_name", shared_name)
1696 _result = _execute.execute(b"BoostedTreesQuantileStreamResourceHandleOp", 1,
1697 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
1698 name=name)
1699 if _execute.must_record_gradient():
1700 _execute.record_gradient(
1701 "BoostedTreesQuantileStreamResourceHandleOp", _inputs_flat, _attrs, _result)
1702 _result, = _result
1703 return _result
1705_BoostedTreesSerializeEnsembleOutput = collections.namedtuple(
1706 "BoostedTreesSerializeEnsemble",
1707 ["stamp_token", "tree_ensemble_serialized"])
1710def boosted_trees_serialize_ensemble(tree_ensemble_handle, name=None):
1711 r"""Serializes the tree ensemble to a proto.
1713 Args:
1714 tree_ensemble_handle: A `Tensor` of type `resource`.
1715 Handle to the tree ensemble.
1716 name: A name for the operation (optional).
1718 Returns:
1719 A tuple of `Tensor` objects (stamp_token, tree_ensemble_serialized).
1721 stamp_token: A `Tensor` of type `int64`.
1722 tree_ensemble_serialized: A `Tensor` of type `string`.
1723 """
1724 _ctx = _context._context or _context.context()
1725 tld = _ctx._thread_local_data
1726 if tld.is_eager:
1727 try:
1728 _result = pywrap_tfe.TFE_Py_FastPathExecute(
1729 _ctx, "BoostedTreesSerializeEnsemble", name, tree_ensemble_handle)
1730 _result = _BoostedTreesSerializeEnsembleOutput._make(_result)
1731 return _result
1732 except _core._NotOkStatusException as e:
1733 _ops.raise_from_not_ok_status(e, name)
1734 except _core._FallbackException:
1735 pass
1736 try:
1737 return boosted_trees_serialize_ensemble_eager_fallback(
1738 tree_ensemble_handle, name=name, ctx=_ctx)
1739 except _core._SymbolicException:
1740 pass # Add nodes to the TensorFlow graph.
1741 # Add nodes to the TensorFlow graph.
1742 _, _, _op, _outputs = _op_def_library._apply_op_helper(
1743 "BoostedTreesSerializeEnsemble", tree_ensemble_handle=tree_ensemble_handle,
1744 name=name)
1745 _result = _outputs[:]
1746 if _execute.must_record_gradient():
1747 _attrs = ()
1748 _inputs_flat = _op.inputs
1749 _execute.record_gradient(
1750 "BoostedTreesSerializeEnsemble", _inputs_flat, _attrs, _result)
1751 _result = _BoostedTreesSerializeEnsembleOutput._make(_result)
1752 return _result
1754BoostedTreesSerializeEnsemble = tf_export("raw_ops.BoostedTreesSerializeEnsemble")(_ops.to_raw_op(boosted_trees_serialize_ensemble))
1757def boosted_trees_serialize_ensemble_eager_fallback(tree_ensemble_handle, name, ctx):
1758 tree_ensemble_handle = _ops.convert_to_tensor(tree_ensemble_handle, _dtypes.resource)
1759 _inputs_flat = [tree_ensemble_handle]
1760 _attrs = None
1761 _result = _execute.execute(b"BoostedTreesSerializeEnsemble", 2,
1762 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
1763 name=name)
1764 if _execute.must_record_gradient():
1765 _execute.record_gradient(
1766 "BoostedTreesSerializeEnsemble", _inputs_flat, _attrs, _result)
1767 _result = _BoostedTreesSerializeEnsembleOutput._make(_result)
1768 return _result
1770_BoostedTreesSparseAggregateStatsOutput = collections.namedtuple(
1771 "BoostedTreesSparseAggregateStats",
1772 ["stats_summary_indices", "stats_summary_values", "stats_summary_shape"])
1775def boosted_trees_sparse_aggregate_stats(node_ids, gradients, hessians, feature_indices, feature_values, feature_shape, max_splits, num_buckets, name=None):
1776 r"""Aggregates the summary of accumulated stats for the batch.
1778 The summary stats contains gradients and hessians accumulated for each node, bucket and dimension id.
1780 Args:
1781 node_ids: A `Tensor` of type `int32`.
1782 int32; Rank 1 Tensor containing node ids for each example, shape [batch_size].
1783 gradients: A `Tensor` of type `float32`.
1784 float32; Rank 2 Tensor (shape=[batch_size, logits_dimension]) with gradients for each example.
1785 hessians: A `Tensor` of type `float32`.
1786 float32; Rank 2 Tensor (shape=[batch_size, hessian_dimension]) with hessians for each example.
1787 feature_indices: A `Tensor` of type `int32`.
1788 int32; Rank 2 indices of feature sparse Tensors (shape=[number of sparse entries, 2]).
1789 Number of sparse entries across all instances from the batch. The first value is
1790 the index of the instance, the second is dimension of the feature. The second axis
1791 can only have 2 values, i.e., the input dense version of Tensor can only be matrix.
1792 feature_values: A `Tensor` of type `int32`.
1793 int32; Rank 1 values of feature sparse Tensors (shape=[number of sparse entries]).
1794 Number of sparse entries across all instances from the batch. The first value is
1795 the index of the instance, the second is dimension of the feature.
1796 feature_shape: A `Tensor` of type `int32`.
1797 int32; Rank 1 dense shape of feature sparse Tensors (shape=[2]).
1798 The first axis can only have 2 values, [batch_size, feature_dimension].
1799 max_splits: An `int` that is `>= 1`.
1800 int; the maximum number of splits possible in the whole tree.
1801 num_buckets: An `int` that is `>= 1`.
1802 int; equals to the maximum possible value of bucketized feature + 1.
1803 name: A name for the operation (optional).
1805 Returns:
1806 A tuple of `Tensor` objects (stats_summary_indices, stats_summary_values, stats_summary_shape).
1808 stats_summary_indices: A `Tensor` of type `int32`.
1809 stats_summary_values: A `Tensor` of type `float32`.
1810 stats_summary_shape: A `Tensor` of type `int32`.
1811 """
1812 _ctx = _context._context or _context.context()
1813 tld = _ctx._thread_local_data
1814 if tld.is_eager:
1815 try:
1816 _result = pywrap_tfe.TFE_Py_FastPathExecute(
1817 _ctx, "BoostedTreesSparseAggregateStats", name, node_ids, gradients,
1818 hessians, feature_indices, feature_values, feature_shape,
1819 "max_splits", max_splits, "num_buckets", num_buckets)
1820 _result = _BoostedTreesSparseAggregateStatsOutput._make(_result)
1821 return _result
1822 except _core._NotOkStatusException as e:
1823 _ops.raise_from_not_ok_status(e, name)
1824 except _core._FallbackException:
1825 pass
1826 try:
1827 return boosted_trees_sparse_aggregate_stats_eager_fallback(
1828 node_ids, gradients, hessians, feature_indices, feature_values,
1829 feature_shape, max_splits=max_splits, num_buckets=num_buckets,
1830 name=name, ctx=_ctx)
1831 except _core._SymbolicException:
1832 pass # Add nodes to the TensorFlow graph.
1833 # Add nodes to the TensorFlow graph.
1834 max_splits = _execute.make_int(max_splits, "max_splits")
1835 num_buckets = _execute.make_int(num_buckets, "num_buckets")
1836 _, _, _op, _outputs = _op_def_library._apply_op_helper(
1837 "BoostedTreesSparseAggregateStats", node_ids=node_ids,
1838 gradients=gradients,
1839 hessians=hessians,
1840 feature_indices=feature_indices,
1841 feature_values=feature_values,
1842 feature_shape=feature_shape,
1843 max_splits=max_splits,
1844 num_buckets=num_buckets,
1845 name=name)
1846 _result = _outputs[:]
1847 if _execute.must_record_gradient():
1848 _attrs = ("max_splits", _op._get_attr_int("max_splits"), "num_buckets",
1849 _op._get_attr_int("num_buckets"))
1850 _inputs_flat = _op.inputs
1851 _execute.record_gradient(
1852 "BoostedTreesSparseAggregateStats", _inputs_flat, _attrs, _result)
1853 _result = _BoostedTreesSparseAggregateStatsOutput._make(_result)
1854 return _result
1856BoostedTreesSparseAggregateStats = tf_export("raw_ops.BoostedTreesSparseAggregateStats")(_ops.to_raw_op(boosted_trees_sparse_aggregate_stats))
1859def boosted_trees_sparse_aggregate_stats_eager_fallback(node_ids, gradients, hessians, feature_indices, feature_values, feature_shape, max_splits, num_buckets, name, ctx):
1860 max_splits = _execute.make_int(max_splits, "max_splits")
1861 num_buckets = _execute.make_int(num_buckets, "num_buckets")
1862 node_ids = _ops.convert_to_tensor(node_ids, _dtypes.int32)
1863 gradients = _ops.convert_to_tensor(gradients, _dtypes.float32)
1864 hessians = _ops.convert_to_tensor(hessians, _dtypes.float32)
1865 feature_indices = _ops.convert_to_tensor(feature_indices, _dtypes.int32)
1866 feature_values = _ops.convert_to_tensor(feature_values, _dtypes.int32)
1867 feature_shape = _ops.convert_to_tensor(feature_shape, _dtypes.int32)
1868 _inputs_flat = [node_ids, gradients, hessians, feature_indices, feature_values, feature_shape]
1869 _attrs = ("max_splits", max_splits, "num_buckets", num_buckets)
1870 _result = _execute.execute(b"BoostedTreesSparseAggregateStats", 3,
1871 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
1872 name=name)
1873 if _execute.must_record_gradient():
1874 _execute.record_gradient(
1875 "BoostedTreesSparseAggregateStats", _inputs_flat, _attrs, _result)
1876 _result = _BoostedTreesSparseAggregateStatsOutput._make(_result)
1877 return _result
1879_BoostedTreesSparseCalculateBestFeatureSplitOutput = collections.namedtuple(
1880 "BoostedTreesSparseCalculateBestFeatureSplit",
1881 ["node_ids", "gains", "feature_dimensions", "thresholds", "left_node_contribs", "right_node_contribs", "split_with_default_directions"])
1884def boosted_trees_sparse_calculate_best_feature_split(node_id_range, stats_summary_indices, stats_summary_values, stats_summary_shape, l1, l2, tree_complexity, min_node_weight, logits_dimension, split_type="inequality", name=None):
1885 r"""Calculates gains for each feature and returns the best possible split information for the feature.
1887 The split information is the best threshold (bucket id), gains and left/right node contributions per node for each feature.
1889 It is possible that not all nodes can be split on each feature. Hence, the list of possible nodes can differ between the features. Therefore, we return `node_ids_list` for each feature, containing the list of nodes that this feature can be used to split.
1891 In this manner, the output is the best split per features and per node, so that it needs to be combined later to produce the best split for each node (among all possible features).
1893 The output shapes are compatible in a way that the first dimension of all tensors are the same and equal to the number of possible split nodes for each feature.
1895 Args:
1896 node_id_range: A `Tensor` of type `int32`.
1897 A Rank 1 tensor (shape=[2]) to specify the range [first, last) of node ids to process within `stats_summary_list`. The nodes are iterated between the two nodes specified by the tensor, as like `for node_id in range(node_id_range[0], node_id_range[1])` (Note that the last index node_id_range[1] is exclusive).
1898 stats_summary_indices: A `Tensor` of type `int32`.
1899 A Rank 2 int64 tensor of dense shape [N, 4] (N specifies the number of non-zero values) for accumulated stats summary (gradient/hessian) per node per bucket for each feature. The second dimension contains node id, feature dimension, bucket id, and stats dim.
1900 stats dim is the sum of logits dimension and hessian dimension, hessian dimension can either be logits dimension if diagonal hessian is used, or logits dimension^2 if full hessian is used.
1901 stats_summary_values: A `Tensor` of type `float32`.
1902 A Rank 1 float tensor of dense shape [N] (N specifies the number of non-zero values), which supplies the values for each element in summary_indices.
1903 stats_summary_shape: A `Tensor` of type `int32`.
1904 A Rank 1 float tensor of dense shape [4], which specifies the dense shape of the sparse tensor, which is [num tree nodes, feature dimensions, num buckets, stats dim].
1905 l1: A `Tensor` of type `float32`.
1906 l1 regularization factor on leaf weights, per instance based.
1907 l2: A `Tensor` of type `float32`.
1908 l2 regularization factor on leaf weights, per instance based.
1909 tree_complexity: A `Tensor` of type `float32`.
1910 adjustment to the gain, per leaf based.
1911 min_node_weight: A `Tensor` of type `float32`.
1912 minimum avg of hessians in a node before required for the node to be considered for splitting.
1913 logits_dimension: An `int` that is `>= 1`.
1914 The dimension of logit, i.e., number of classes.
1915 split_type: An optional `string` from: `"inequality"`. Defaults to `"inequality"`.
1916 A string indicating if this Op should perform inequality split or equality split.
1917 name: A name for the operation (optional).
1919 Returns:
1920 A tuple of `Tensor` objects (node_ids, gains, feature_dimensions, thresholds, left_node_contribs, right_node_contribs, split_with_default_directions).
1922 node_ids: A `Tensor` of type `int32`.
1923 gains: A `Tensor` of type `float32`.
1924 feature_dimensions: A `Tensor` of type `int32`.
1925 thresholds: A `Tensor` of type `int32`.
1926 left_node_contribs: A `Tensor` of type `float32`.
1927 right_node_contribs: A `Tensor` of type `float32`.
1928 split_with_default_directions: A `Tensor` of type `string`.
1929 """
1930 _ctx = _context._context or _context.context()
1931 tld = _ctx._thread_local_data
1932 if tld.is_eager:
1933 try:
1934 _result = pywrap_tfe.TFE_Py_FastPathExecute(
1935 _ctx, "BoostedTreesSparseCalculateBestFeatureSplit", name,
1936 node_id_range, stats_summary_indices, stats_summary_values,
1937 stats_summary_shape, l1, l2, tree_complexity, min_node_weight,
1938 "logits_dimension", logits_dimension, "split_type", split_type)
1939 _result = _BoostedTreesSparseCalculateBestFeatureSplitOutput._make(_result)
1940 return _result
1941 except _core._NotOkStatusException as e:
1942 _ops.raise_from_not_ok_status(e, name)
1943 except _core._FallbackException:
1944 pass
1945 try:
1946 return boosted_trees_sparse_calculate_best_feature_split_eager_fallback(
1947 node_id_range, stats_summary_indices, stats_summary_values,
1948 stats_summary_shape, l1, l2, tree_complexity, min_node_weight,
1949 logits_dimension=logits_dimension, split_type=split_type, name=name,
1950 ctx=_ctx)
1951 except _core._SymbolicException:
1952 pass # Add nodes to the TensorFlow graph.
1953 # Add nodes to the TensorFlow graph.
1954 logits_dimension = _execute.make_int(logits_dimension, "logits_dimension")
1955 if split_type is None:
1956 split_type = "inequality"
1957 split_type = _execute.make_str(split_type, "split_type")
1958 _, _, _op, _outputs = _op_def_library._apply_op_helper(
1959 "BoostedTreesSparseCalculateBestFeatureSplit", node_id_range=node_id_range,
1960 stats_summary_indices=stats_summary_indices,
1961 stats_summary_values=stats_summary_values,
1962 stats_summary_shape=stats_summary_shape,
1963 l1=l1, l2=l2,
1964 tree_complexity=tree_complexity,
1965 min_node_weight=min_node_weight,
1966 logits_dimension=logits_dimension,
1967 split_type=split_type,
1968 name=name)
1969 _result = _outputs[:]
1970 if _execute.must_record_gradient():
1971 _attrs = ("logits_dimension", _op._get_attr_int("logits_dimension"),
1972 "split_type", _op.get_attr("split_type"))
1973 _inputs_flat = _op.inputs
1974 _execute.record_gradient(
1975 "BoostedTreesSparseCalculateBestFeatureSplit", _inputs_flat, _attrs, _result)
1976 _result = _BoostedTreesSparseCalculateBestFeatureSplitOutput._make(_result)
1977 return _result
1979BoostedTreesSparseCalculateBestFeatureSplit = tf_export("raw_ops.BoostedTreesSparseCalculateBestFeatureSplit")(_ops.to_raw_op(boosted_trees_sparse_calculate_best_feature_split))
1982def boosted_trees_sparse_calculate_best_feature_split_eager_fallback(node_id_range, stats_summary_indices, stats_summary_values, stats_summary_shape, l1, l2, tree_complexity, min_node_weight, logits_dimension, split_type, name, ctx):
1983 logits_dimension = _execute.make_int(logits_dimension, "logits_dimension")
1984 if split_type is None:
1985 split_type = "inequality"
1986 split_type = _execute.make_str(split_type, "split_type")
1987 node_id_range = _ops.convert_to_tensor(node_id_range, _dtypes.int32)
1988 stats_summary_indices = _ops.convert_to_tensor(stats_summary_indices, _dtypes.int32)
1989 stats_summary_values = _ops.convert_to_tensor(stats_summary_values, _dtypes.float32)
1990 stats_summary_shape = _ops.convert_to_tensor(stats_summary_shape, _dtypes.int32)
1991 l1 = _ops.convert_to_tensor(l1, _dtypes.float32)
1992 l2 = _ops.convert_to_tensor(l2, _dtypes.float32)
1993 tree_complexity = _ops.convert_to_tensor(tree_complexity, _dtypes.float32)
1994 min_node_weight = _ops.convert_to_tensor(min_node_weight, _dtypes.float32)
1995 _inputs_flat = [node_id_range, stats_summary_indices, stats_summary_values, stats_summary_shape, l1, l2, tree_complexity, min_node_weight]
1996 _attrs = ("logits_dimension", logits_dimension, "split_type", split_type)
1997 _result = _execute.execute(b"BoostedTreesSparseCalculateBestFeatureSplit",
1998 7, inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
1999 name=name)
2000 if _execute.must_record_gradient():
2001 _execute.record_gradient(
2002 "BoostedTreesSparseCalculateBestFeatureSplit", _inputs_flat, _attrs, _result)
2003 _result = _BoostedTreesSparseCalculateBestFeatureSplitOutput._make(_result)
2004 return _result
2006_BoostedTreesTrainingPredictOutput = collections.namedtuple(
2007 "BoostedTreesTrainingPredict",
2008 ["partial_logits", "tree_ids", "node_ids"])
2011def boosted_trees_training_predict(tree_ensemble_handle, cached_tree_ids, cached_node_ids, bucketized_features, logits_dimension, name=None):
2012 r"""Runs multiple additive regression ensemble predictors on input instances and
2014 computes the update to cached logits. It is designed to be used during training.
2015 It traverses the trees starting from cached tree id and cached node id and
2016 calculates the updates to be pushed to the cache.
2018 Args:
2019 tree_ensemble_handle: A `Tensor` of type `resource`.
2020 cached_tree_ids: A `Tensor` of type `int32`.
2021 Rank 1 Tensor containing cached tree ids which is the starting
2022 tree of prediction.
2023 cached_node_ids: A `Tensor` of type `int32`.
2024 Rank 1 Tensor containing cached node id which is the starting
2025 node of prediction.
2026 bucketized_features: A list of at least 1 `Tensor` objects with type `int32`.
2027 A list of rank 1 Tensors containing bucket id for each
2028 feature.
2029 logits_dimension: An `int`.
2030 scalar, dimension of the logits, to be used for partial logits
2031 shape.
2032 name: A name for the operation (optional).
2034 Returns:
2035 A tuple of `Tensor` objects (partial_logits, tree_ids, node_ids).
2037 partial_logits: A `Tensor` of type `float32`.
2038 tree_ids: A `Tensor` of type `int32`.
2039 node_ids: A `Tensor` of type `int32`.
2040 """
2041 _ctx = _context._context or _context.context()
2042 tld = _ctx._thread_local_data
2043 if tld.is_eager:
2044 try:
2045 _result = pywrap_tfe.TFE_Py_FastPathExecute(
2046 _ctx, "BoostedTreesTrainingPredict", name, tree_ensemble_handle,
2047 cached_tree_ids, cached_node_ids, bucketized_features,
2048 "logits_dimension", logits_dimension)
2049 _result = _BoostedTreesTrainingPredictOutput._make(_result)
2050 return _result
2051 except _core._NotOkStatusException as e:
2052 _ops.raise_from_not_ok_status(e, name)
2053 except _core._FallbackException:
2054 pass
2055 try:
2056 return boosted_trees_training_predict_eager_fallback(
2057 tree_ensemble_handle, cached_tree_ids, cached_node_ids,
2058 bucketized_features, logits_dimension=logits_dimension, name=name,
2059 ctx=_ctx)
2060 except _core._SymbolicException:
2061 pass # Add nodes to the TensorFlow graph.
2062 # Add nodes to the TensorFlow graph.
2063 if not isinstance(bucketized_features, (list, tuple)):
2064 raise TypeError(
2065 "Expected list for 'bucketized_features' argument to "
2066 "'boosted_trees_training_predict' Op, not %r." % bucketized_features)
2067 _attr_num_bucketized_features = len(bucketized_features)
2068 logits_dimension = _execute.make_int(logits_dimension, "logits_dimension")
2069 _, _, _op, _outputs = _op_def_library._apply_op_helper(
2070 "BoostedTreesTrainingPredict", tree_ensemble_handle=tree_ensemble_handle,
2071 cached_tree_ids=cached_tree_ids,
2072 cached_node_ids=cached_node_ids,
2073 bucketized_features=bucketized_features,
2074 logits_dimension=logits_dimension,
2075 name=name)
2076 _result = _outputs[:]
2077 if _execute.must_record_gradient():
2078 _attrs = ("num_bucketized_features",
2079 _op._get_attr_int("num_bucketized_features"),
2080 "logits_dimension", _op._get_attr_int("logits_dimension"))
2081 _inputs_flat = _op.inputs
2082 _execute.record_gradient(
2083 "BoostedTreesTrainingPredict", _inputs_flat, _attrs, _result)
2084 _result = _BoostedTreesTrainingPredictOutput._make(_result)
2085 return _result
2087BoostedTreesTrainingPredict = tf_export("raw_ops.BoostedTreesTrainingPredict")(_ops.to_raw_op(boosted_trees_training_predict))
2090def boosted_trees_training_predict_eager_fallback(tree_ensemble_handle, cached_tree_ids, cached_node_ids, bucketized_features, logits_dimension, name, ctx):
2091 if not isinstance(bucketized_features, (list, tuple)):
2092 raise TypeError(
2093 "Expected list for 'bucketized_features' argument to "
2094 "'boosted_trees_training_predict' Op, not %r." % bucketized_features)
2095 _attr_num_bucketized_features = len(bucketized_features)
2096 logits_dimension = _execute.make_int(logits_dimension, "logits_dimension")
2097 tree_ensemble_handle = _ops.convert_to_tensor(tree_ensemble_handle, _dtypes.resource)
2098 cached_tree_ids = _ops.convert_to_tensor(cached_tree_ids, _dtypes.int32)
2099 cached_node_ids = _ops.convert_to_tensor(cached_node_ids, _dtypes.int32)
2100 bucketized_features = _ops.convert_n_to_tensor(bucketized_features, _dtypes.int32)
2101 _inputs_flat = [tree_ensemble_handle, cached_tree_ids, cached_node_ids] + list(bucketized_features)
2102 _attrs = ("num_bucketized_features", _attr_num_bucketized_features,
2103 "logits_dimension", logits_dimension)
2104 _result = _execute.execute(b"BoostedTreesTrainingPredict", 3,
2105 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
2106 name=name)
2107 if _execute.must_record_gradient():
2108 _execute.record_gradient(
2109 "BoostedTreesTrainingPredict", _inputs_flat, _attrs, _result)
2110 _result = _BoostedTreesTrainingPredictOutput._make(_result)
2111 return _result
2114def boosted_trees_update_ensemble(tree_ensemble_handle, feature_ids, node_ids, gains, thresholds, left_node_contribs, right_node_contribs, max_depth, learning_rate, pruning_mode, name=None):
2115 r"""Updates the tree ensemble by either adding a layer to the last tree being grown
2117 or by starting a new tree.
2119 Args:
2120 tree_ensemble_handle: A `Tensor` of type `resource`.
2121 Handle to the ensemble variable.
2122 feature_ids: A `Tensor` of type `int32`.
2123 Rank 1 tensor with ids for each feature. This is the real id of
2124 the feature that will be used in the split.
2125 node_ids: A list of `Tensor` objects with type `int32`.
2126 List of rank 1 tensors representing the nodes for which this feature
2127 has a split.
2128 gains: A list with the same length as `node_ids` of `Tensor` objects with type `float32`.
2129 List of rank 1 tensors representing the gains for each of the feature's
2130 split.
2131 thresholds: A list with the same length as `node_ids` of `Tensor` objects with type `int32`.
2132 List of rank 1 tensors representing the thesholds for each of the
2133 feature's split.
2134 left_node_contribs: A list with the same length as `node_ids` of `Tensor` objects with type `float32`.
2135 List of rank 2 tensors with left leaf contribs for each of
2136 the feature's splits. Will be added to the previous node values to constitute
2137 the values of the left nodes.
2138 right_node_contribs: A list with the same length as `node_ids` of `Tensor` objects with type `float32`.
2139 List of rank 2 tensors with right leaf contribs for each
2140 of the feature's splits. Will be added to the previous node values to constitute
2141 the values of the right nodes.
2142 max_depth: A `Tensor` of type `int32`. Max depth of the tree to build.
2143 learning_rate: A `Tensor` of type `float32`.
2144 shrinkage const for each new tree.
2145 pruning_mode: An `int` that is `>= 0`.
2146 0-No pruning, 1-Pre-pruning, 2-Post-pruning.
2147 name: A name for the operation (optional).
2149 Returns:
2150 The created Operation.
2151 """
2152 _ctx = _context._context or _context.context()
2153 tld = _ctx._thread_local_data
2154 if tld.is_eager:
2155 try:
2156 _result = pywrap_tfe.TFE_Py_FastPathExecute(
2157 _ctx, "BoostedTreesUpdateEnsemble", name, tree_ensemble_handle,
2158 feature_ids, node_ids, gains, thresholds, left_node_contribs,
2159 right_node_contribs, max_depth, learning_rate, "pruning_mode",
2160 pruning_mode)
2161 return _result
2162 except _core._NotOkStatusException as e:
2163 _ops.raise_from_not_ok_status(e, name)
2164 except _core._FallbackException:
2165 pass
2166 try:
2167 return boosted_trees_update_ensemble_eager_fallback(
2168 tree_ensemble_handle, feature_ids, node_ids, gains, thresholds,
2169 left_node_contribs, right_node_contribs, max_depth, learning_rate,
2170 pruning_mode=pruning_mode, name=name, ctx=_ctx)
2171 except _core._SymbolicException:
2172 pass # Add nodes to the TensorFlow graph.
2173 # Add nodes to the TensorFlow graph.
2174 if not isinstance(node_ids, (list, tuple)):
2175 raise TypeError(
2176 "Expected list for 'node_ids' argument to "
2177 "'boosted_trees_update_ensemble' Op, not %r." % node_ids)
2178 _attr_num_features = len(node_ids)
2179 if not isinstance(gains, (list, tuple)):
2180 raise TypeError(
2181 "Expected list for 'gains' argument to "
2182 "'boosted_trees_update_ensemble' Op, not %r." % gains)
2183 if len(gains) != _attr_num_features:
2184 raise ValueError(
2185 "List argument 'gains' to 'boosted_trees_update_ensemble' Op with length %d "
2186 "must match length %d of argument 'node_ids'." %
2187 (len(gains), _attr_num_features))
2188 if not isinstance(thresholds, (list, tuple)):
2189 raise TypeError(
2190 "Expected list for 'thresholds' argument to "
2191 "'boosted_trees_update_ensemble' Op, not %r." % thresholds)
2192 if len(thresholds) != _attr_num_features:
2193 raise ValueError(
2194 "List argument 'thresholds' to 'boosted_trees_update_ensemble' Op with length %d "
2195 "must match length %d of argument 'node_ids'." %
2196 (len(thresholds), _attr_num_features))
2197 if not isinstance(left_node_contribs, (list, tuple)):
2198 raise TypeError(
2199 "Expected list for 'left_node_contribs' argument to "
2200 "'boosted_trees_update_ensemble' Op, not %r." % left_node_contribs)
2201 if len(left_node_contribs) != _attr_num_features:
2202 raise ValueError(
2203 "List argument 'left_node_contribs' to 'boosted_trees_update_ensemble' Op with length %d "
2204 "must match length %d of argument 'node_ids'." %
2205 (len(left_node_contribs), _attr_num_features))
2206 if not isinstance(right_node_contribs, (list, tuple)):
2207 raise TypeError(
2208 "Expected list for 'right_node_contribs' argument to "
2209 "'boosted_trees_update_ensemble' Op, not %r." % right_node_contribs)
2210 if len(right_node_contribs) != _attr_num_features:
2211 raise ValueError(
2212 "List argument 'right_node_contribs' to 'boosted_trees_update_ensemble' Op with length %d "
2213 "must match length %d of argument 'node_ids'." %
2214 (len(right_node_contribs), _attr_num_features))
2215 pruning_mode = _execute.make_int(pruning_mode, "pruning_mode")
2216 _, _, _op, _outputs = _op_def_library._apply_op_helper(
2217 "BoostedTreesUpdateEnsemble", tree_ensemble_handle=tree_ensemble_handle,
2218 feature_ids=feature_ids,
2219 node_ids=node_ids, gains=gains,
2220 thresholds=thresholds,
2221 left_node_contribs=left_node_contribs,
2222 right_node_contribs=right_node_contribs,
2223 max_depth=max_depth,
2224 learning_rate=learning_rate,
2225 pruning_mode=pruning_mode, name=name)
2226 return _op
2227BoostedTreesUpdateEnsemble = tf_export("raw_ops.BoostedTreesUpdateEnsemble")(_ops.to_raw_op(boosted_trees_update_ensemble))
2230def boosted_trees_update_ensemble_eager_fallback(tree_ensemble_handle, feature_ids, node_ids, gains, thresholds, left_node_contribs, right_node_contribs, max_depth, learning_rate, pruning_mode, name, ctx):
2231 if not isinstance(node_ids, (list, tuple)):
2232 raise TypeError(
2233 "Expected list for 'node_ids' argument to "
2234 "'boosted_trees_update_ensemble' Op, not %r." % node_ids)
2235 _attr_num_features = len(node_ids)
2236 if not isinstance(gains, (list, tuple)):
2237 raise TypeError(
2238 "Expected list for 'gains' argument to "
2239 "'boosted_trees_update_ensemble' Op, not %r." % gains)
2240 if len(gains) != _attr_num_features:
2241 raise ValueError(
2242 "List argument 'gains' to 'boosted_trees_update_ensemble' Op with length %d "
2243 "must match length %d of argument 'node_ids'." %
2244 (len(gains), _attr_num_features))
2245 if not isinstance(thresholds, (list, tuple)):
2246 raise TypeError(
2247 "Expected list for 'thresholds' argument to "
2248 "'boosted_trees_update_ensemble' Op, not %r." % thresholds)
2249 if len(thresholds) != _attr_num_features:
2250 raise ValueError(
2251 "List argument 'thresholds' to 'boosted_trees_update_ensemble' Op with length %d "
2252 "must match length %d of argument 'node_ids'." %
2253 (len(thresholds), _attr_num_features))
2254 if not isinstance(left_node_contribs, (list, tuple)):
2255 raise TypeError(
2256 "Expected list for 'left_node_contribs' argument to "
2257 "'boosted_trees_update_ensemble' Op, not %r." % left_node_contribs)
2258 if len(left_node_contribs) != _attr_num_features:
2259 raise ValueError(
2260 "List argument 'left_node_contribs' to 'boosted_trees_update_ensemble' Op with length %d "
2261 "must match length %d of argument 'node_ids'." %
2262 (len(left_node_contribs), _attr_num_features))
2263 if not isinstance(right_node_contribs, (list, tuple)):
2264 raise TypeError(
2265 "Expected list for 'right_node_contribs' argument to "
2266 "'boosted_trees_update_ensemble' Op, not %r." % right_node_contribs)
2267 if len(right_node_contribs) != _attr_num_features:
2268 raise ValueError(
2269 "List argument 'right_node_contribs' to 'boosted_trees_update_ensemble' Op with length %d "
2270 "must match length %d of argument 'node_ids'." %
2271 (len(right_node_contribs), _attr_num_features))
2272 pruning_mode = _execute.make_int(pruning_mode, "pruning_mode")
2273 tree_ensemble_handle = _ops.convert_to_tensor(tree_ensemble_handle, _dtypes.resource)
2274 feature_ids = _ops.convert_to_tensor(feature_ids, _dtypes.int32)
2275 node_ids = _ops.convert_n_to_tensor(node_ids, _dtypes.int32)
2276 gains = _ops.convert_n_to_tensor(gains, _dtypes.float32)
2277 thresholds = _ops.convert_n_to_tensor(thresholds, _dtypes.int32)
2278 left_node_contribs = _ops.convert_n_to_tensor(left_node_contribs, _dtypes.float32)
2279 right_node_contribs = _ops.convert_n_to_tensor(right_node_contribs, _dtypes.float32)
2280 max_depth = _ops.convert_to_tensor(max_depth, _dtypes.int32)
2281 learning_rate = _ops.convert_to_tensor(learning_rate, _dtypes.float32)
2282 _inputs_flat = [tree_ensemble_handle, feature_ids] + list(node_ids) + list(gains) + list(thresholds) + list(left_node_contribs) + list(right_node_contribs) + [max_depth, learning_rate]
2283 _attrs = ("pruning_mode", pruning_mode, "num_features", _attr_num_features)
2284 _result = _execute.execute(b"BoostedTreesUpdateEnsemble", 0,
2285 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
2286 name=name)
2287 _result = None
2288 return _result
2291def boosted_trees_update_ensemble_v2(tree_ensemble_handle, feature_ids, dimension_ids, node_ids, gains, thresholds, left_node_contribs, right_node_contribs, split_types, max_depth, learning_rate, pruning_mode, logits_dimension=1, name=None):
2292 r"""Updates the tree ensemble by adding a layer to the last tree being grown
2294 or by starting a new tree.
2296 Args:
2297 tree_ensemble_handle: A `Tensor` of type `resource`.
2298 Handle to the ensemble variable.
2299 feature_ids: A list of at least 1 `Tensor` objects with type `int32`.
2300 Rank 1 tensor with ids for each feature. This is the real id of
2301 the feature that will be used in the split.
2302 dimension_ids: A list of `Tensor` objects with type `int32`.
2303 List of rank 1 tensors representing the dimension in each feature.
2304 node_ids: A list with the same length as `dimension_ids` of `Tensor` objects with type `int32`.
2305 List of rank 1 tensors representing the nodes for which this feature
2306 has a split.
2307 gains: A list with the same length as `dimension_ids` of `Tensor` objects with type `float32`.
2308 List of rank 1 tensors representing the gains for each of the feature's
2309 split.
2310 thresholds: A list with the same length as `dimension_ids` of `Tensor` objects with type `int32`.
2311 List of rank 1 tensors representing the thesholds for each of the
2312 feature's split.
2313 left_node_contribs: A list with the same length as `dimension_ids` of `Tensor` objects with type `float32`.
2314 List of rank 2 tensors with left leaf contribs for each of
2315 the feature's splits. Will be added to the previous node values to constitute
2316 the values of the left nodes.
2317 right_node_contribs: A list with the same length as `dimension_ids` of `Tensor` objects with type `float32`.
2318 List of rank 2 tensors with right leaf contribs for each
2319 of the feature's splits. Will be added to the previous node values to constitute
2320 the values of the right nodes.
2321 split_types: A list with the same length as `dimension_ids` of `Tensor` objects with type `string`.
2322 List of rank 1 tensors representing the split type for each feature.
2323 max_depth: A `Tensor` of type `int32`. Max depth of the tree to build.
2324 learning_rate: A `Tensor` of type `float32`.
2325 shrinkage const for each new tree.
2326 pruning_mode: A `Tensor` of type `int32`.
2327 0-No pruning, 1-Pre-pruning, 2-Post-pruning.
2328 logits_dimension: An optional `int`. Defaults to `1`.
2329 scalar, dimension of the logits
2330 name: A name for the operation (optional).
2332 Returns:
2333 The created Operation.
2334 """
2335 _ctx = _context._context or _context.context()
2336 tld = _ctx._thread_local_data
2337 if tld.is_eager:
2338 try:
2339 _result = pywrap_tfe.TFE_Py_FastPathExecute(
2340 _ctx, "BoostedTreesUpdateEnsembleV2", name, tree_ensemble_handle,
2341 feature_ids, dimension_ids, node_ids, gains, thresholds,
2342 left_node_contribs, right_node_contribs, split_types, max_depth,
2343 learning_rate, pruning_mode, "logits_dimension", logits_dimension)
2344 return _result
2345 except _core._NotOkStatusException as e:
2346 _ops.raise_from_not_ok_status(e, name)
2347 except _core._FallbackException:
2348 pass
2349 try:
2350 return boosted_trees_update_ensemble_v2_eager_fallback(
2351 tree_ensemble_handle, feature_ids, dimension_ids, node_ids, gains,
2352 thresholds, left_node_contribs, right_node_contribs, split_types,
2353 max_depth, learning_rate, pruning_mode,
2354 logits_dimension=logits_dimension, name=name, ctx=_ctx)
2355 except _core._SymbolicException:
2356 pass # Add nodes to the TensorFlow graph.
2357 # Add nodes to the TensorFlow graph.
2358 if not isinstance(dimension_ids, (list, tuple)):
2359 raise TypeError(
2360 "Expected list for 'dimension_ids' argument to "
2361 "'boosted_trees_update_ensemble_v2' Op, not %r." % dimension_ids)
2362 _attr_num_features = len(dimension_ids)
2363 if not isinstance(node_ids, (list, tuple)):
2364 raise TypeError(
2365 "Expected list for 'node_ids' argument to "
2366 "'boosted_trees_update_ensemble_v2' Op, not %r." % node_ids)
2367 if len(node_ids) != _attr_num_features:
2368 raise ValueError(
2369 "List argument 'node_ids' to 'boosted_trees_update_ensemble_v2' Op with length %d "
2370 "must match length %d of argument 'dimension_ids'." %
2371 (len(node_ids), _attr_num_features))
2372 if not isinstance(gains, (list, tuple)):
2373 raise TypeError(
2374 "Expected list for 'gains' argument to "
2375 "'boosted_trees_update_ensemble_v2' Op, not %r." % gains)
2376 if len(gains) != _attr_num_features:
2377 raise ValueError(
2378 "List argument 'gains' to 'boosted_trees_update_ensemble_v2' Op with length %d "
2379 "must match length %d of argument 'dimension_ids'." %
2380 (len(gains), _attr_num_features))
2381 if not isinstance(thresholds, (list, tuple)):
2382 raise TypeError(
2383 "Expected list for 'thresholds' argument to "
2384 "'boosted_trees_update_ensemble_v2' Op, not %r." % thresholds)
2385 if len(thresholds) != _attr_num_features:
2386 raise ValueError(
2387 "List argument 'thresholds' to 'boosted_trees_update_ensemble_v2' Op with length %d "
2388 "must match length %d of argument 'dimension_ids'." %
2389 (len(thresholds), _attr_num_features))
2390 if not isinstance(left_node_contribs, (list, tuple)):
2391 raise TypeError(
2392 "Expected list for 'left_node_contribs' argument to "
2393 "'boosted_trees_update_ensemble_v2' Op, not %r." % left_node_contribs)
2394 if len(left_node_contribs) != _attr_num_features:
2395 raise ValueError(
2396 "List argument 'left_node_contribs' to 'boosted_trees_update_ensemble_v2' Op with length %d "
2397 "must match length %d of argument 'dimension_ids'." %
2398 (len(left_node_contribs), _attr_num_features))
2399 if not isinstance(right_node_contribs, (list, tuple)):
2400 raise TypeError(
2401 "Expected list for 'right_node_contribs' argument to "
2402 "'boosted_trees_update_ensemble_v2' Op, not %r." % right_node_contribs)
2403 if len(right_node_contribs) != _attr_num_features:
2404 raise ValueError(
2405 "List argument 'right_node_contribs' to 'boosted_trees_update_ensemble_v2' Op with length %d "
2406 "must match length %d of argument 'dimension_ids'." %
2407 (len(right_node_contribs), _attr_num_features))
2408 if not isinstance(split_types, (list, tuple)):
2409 raise TypeError(
2410 "Expected list for 'split_types' argument to "
2411 "'boosted_trees_update_ensemble_v2' Op, not %r." % split_types)
2412 if len(split_types) != _attr_num_features:
2413 raise ValueError(
2414 "List argument 'split_types' to 'boosted_trees_update_ensemble_v2' Op with length %d "
2415 "must match length %d of argument 'dimension_ids'." %
2416 (len(split_types), _attr_num_features))
2417 if not isinstance(feature_ids, (list, tuple)):
2418 raise TypeError(
2419 "Expected list for 'feature_ids' argument to "
2420 "'boosted_trees_update_ensemble_v2' Op, not %r." % feature_ids)
2421 _attr_num_groups = len(feature_ids)
2422 if logits_dimension is None:
2423 logits_dimension = 1
2424 logits_dimension = _execute.make_int(logits_dimension, "logits_dimension")
2425 _, _, _op, _outputs = _op_def_library._apply_op_helper(
2426 "BoostedTreesUpdateEnsembleV2", tree_ensemble_handle=tree_ensemble_handle,
2427 feature_ids=feature_ids,
2428 dimension_ids=dimension_ids,
2429 node_ids=node_ids, gains=gains,
2430 thresholds=thresholds,
2431 left_node_contribs=left_node_contribs,
2432 right_node_contribs=right_node_contribs,
2433 split_types=split_types,
2434 max_depth=max_depth,
2435 learning_rate=learning_rate,
2436 pruning_mode=pruning_mode,
2437 logits_dimension=logits_dimension,
2438 name=name)
2439 return _op
2440BoostedTreesUpdateEnsembleV2 = tf_export("raw_ops.BoostedTreesUpdateEnsembleV2")(_ops.to_raw_op(boosted_trees_update_ensemble_v2))
2443def boosted_trees_update_ensemble_v2_eager_fallback(tree_ensemble_handle, feature_ids, dimension_ids, node_ids, gains, thresholds, left_node_contribs, right_node_contribs, split_types, max_depth, learning_rate, pruning_mode, logits_dimension, name, ctx):
2444 if not isinstance(dimension_ids, (list, tuple)):
2445 raise TypeError(
2446 "Expected list for 'dimension_ids' argument to "
2447 "'boosted_trees_update_ensemble_v2' Op, not %r." % dimension_ids)
2448 _attr_num_features = len(dimension_ids)
2449 if not isinstance(node_ids, (list, tuple)):
2450 raise TypeError(
2451 "Expected list for 'node_ids' argument to "
2452 "'boosted_trees_update_ensemble_v2' Op, not %r." % node_ids)
2453 if len(node_ids) != _attr_num_features:
2454 raise ValueError(
2455 "List argument 'node_ids' to 'boosted_trees_update_ensemble_v2' Op with length %d "
2456 "must match length %d of argument 'dimension_ids'." %
2457 (len(node_ids), _attr_num_features))
2458 if not isinstance(gains, (list, tuple)):
2459 raise TypeError(
2460 "Expected list for 'gains' argument to "
2461 "'boosted_trees_update_ensemble_v2' Op, not %r." % gains)
2462 if len(gains) != _attr_num_features:
2463 raise ValueError(
2464 "List argument 'gains' to 'boosted_trees_update_ensemble_v2' Op with length %d "
2465 "must match length %d of argument 'dimension_ids'." %
2466 (len(gains), _attr_num_features))
2467 if not isinstance(thresholds, (list, tuple)):
2468 raise TypeError(
2469 "Expected list for 'thresholds' argument to "
2470 "'boosted_trees_update_ensemble_v2' Op, not %r." % thresholds)
2471 if len(thresholds) != _attr_num_features:
2472 raise ValueError(
2473 "List argument 'thresholds' to 'boosted_trees_update_ensemble_v2' Op with length %d "
2474 "must match length %d of argument 'dimension_ids'." %
2475 (len(thresholds), _attr_num_features))
2476 if not isinstance(left_node_contribs, (list, tuple)):
2477 raise TypeError(
2478 "Expected list for 'left_node_contribs' argument to "
2479 "'boosted_trees_update_ensemble_v2' Op, not %r." % left_node_contribs)
2480 if len(left_node_contribs) != _attr_num_features:
2481 raise ValueError(
2482 "List argument 'left_node_contribs' to 'boosted_trees_update_ensemble_v2' Op with length %d "
2483 "must match length %d of argument 'dimension_ids'." %
2484 (len(left_node_contribs), _attr_num_features))
2485 if not isinstance(right_node_contribs, (list, tuple)):
2486 raise TypeError(
2487 "Expected list for 'right_node_contribs' argument to "
2488 "'boosted_trees_update_ensemble_v2' Op, not %r." % right_node_contribs)
2489 if len(right_node_contribs) != _attr_num_features:
2490 raise ValueError(
2491 "List argument 'right_node_contribs' to 'boosted_trees_update_ensemble_v2' Op with length %d "
2492 "must match length %d of argument 'dimension_ids'." %
2493 (len(right_node_contribs), _attr_num_features))
2494 if not isinstance(split_types, (list, tuple)):
2495 raise TypeError(
2496 "Expected list for 'split_types' argument to "
2497 "'boosted_trees_update_ensemble_v2' Op, not %r." % split_types)
2498 if len(split_types) != _attr_num_features:
2499 raise ValueError(
2500 "List argument 'split_types' to 'boosted_trees_update_ensemble_v2' Op with length %d "
2501 "must match length %d of argument 'dimension_ids'." %
2502 (len(split_types), _attr_num_features))
2503 if not isinstance(feature_ids, (list, tuple)):
2504 raise TypeError(
2505 "Expected list for 'feature_ids' argument to "
2506 "'boosted_trees_update_ensemble_v2' Op, not %r." % feature_ids)
2507 _attr_num_groups = len(feature_ids)
2508 if logits_dimension is None:
2509 logits_dimension = 1
2510 logits_dimension = _execute.make_int(logits_dimension, "logits_dimension")
2511 tree_ensemble_handle = _ops.convert_to_tensor(tree_ensemble_handle, _dtypes.resource)
2512 feature_ids = _ops.convert_n_to_tensor(feature_ids, _dtypes.int32)
2513 dimension_ids = _ops.convert_n_to_tensor(dimension_ids, _dtypes.int32)
2514 node_ids = _ops.convert_n_to_tensor(node_ids, _dtypes.int32)
2515 gains = _ops.convert_n_to_tensor(gains, _dtypes.float32)
2516 thresholds = _ops.convert_n_to_tensor(thresholds, _dtypes.int32)
2517 left_node_contribs = _ops.convert_n_to_tensor(left_node_contribs, _dtypes.float32)
2518 right_node_contribs = _ops.convert_n_to_tensor(right_node_contribs, _dtypes.float32)
2519 split_types = _ops.convert_n_to_tensor(split_types, _dtypes.string)
2520 max_depth = _ops.convert_to_tensor(max_depth, _dtypes.int32)
2521 learning_rate = _ops.convert_to_tensor(learning_rate, _dtypes.float32)
2522 pruning_mode = _ops.convert_to_tensor(pruning_mode, _dtypes.int32)
2523 _inputs_flat = [tree_ensemble_handle] + list(feature_ids) + list(dimension_ids) + list(node_ids) + list(gains) + list(thresholds) + list(left_node_contribs) + list(right_node_contribs) + list(split_types) + [max_depth, learning_rate, pruning_mode]
2524 _attrs = ("num_features", _attr_num_features, "logits_dimension",
2525 logits_dimension, "num_groups", _attr_num_groups)
2526 _result = _execute.execute(b"BoostedTreesUpdateEnsembleV2", 0,
2527 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
2528 name=name)
2529 _result = None
2530 return _result
2533def is_boosted_trees_ensemble_initialized(tree_ensemble_handle, name=None):
2534 r"""Checks whether a tree ensemble has been initialized.
2536 Args:
2537 tree_ensemble_handle: A `Tensor` of type `resource`.
2538 Handle to the tree ensemble resource.
2539 name: A name for the operation (optional).
2541 Returns:
2542 A `Tensor` of type `bool`.
2543 """
2544 _ctx = _context._context or _context.context()
2545 tld = _ctx._thread_local_data
2546 if tld.is_eager:
2547 try:
2548 _result = pywrap_tfe.TFE_Py_FastPathExecute(
2549 _ctx, "IsBoostedTreesEnsembleInitialized", name, tree_ensemble_handle)
2550 return _result
2551 except _core._NotOkStatusException as e:
2552 _ops.raise_from_not_ok_status(e, name)
2553 except _core._FallbackException:
2554 pass
2555 try:
2556 return is_boosted_trees_ensemble_initialized_eager_fallback(
2557 tree_ensemble_handle, name=name, ctx=_ctx)
2558 except _core._SymbolicException:
2559 pass # Add nodes to the TensorFlow graph.
2560 # Add nodes to the TensorFlow graph.
2561 _, _, _op, _outputs = _op_def_library._apply_op_helper(
2562 "IsBoostedTreesEnsembleInitialized", tree_ensemble_handle=tree_ensemble_handle,
2563 name=name)
2564 _result = _outputs[:]
2565 if _execute.must_record_gradient():
2566 _attrs = ()
2567 _inputs_flat = _op.inputs
2568 _execute.record_gradient(
2569 "IsBoostedTreesEnsembleInitialized", _inputs_flat, _attrs, _result)
2570 _result, = _result
2571 return _result
2573IsBoostedTreesEnsembleInitialized = tf_export("raw_ops.IsBoostedTreesEnsembleInitialized")(_ops.to_raw_op(is_boosted_trees_ensemble_initialized))
2576def is_boosted_trees_ensemble_initialized_eager_fallback(tree_ensemble_handle, name, ctx):
2577 tree_ensemble_handle = _ops.convert_to_tensor(tree_ensemble_handle, _dtypes.resource)
2578 _inputs_flat = [tree_ensemble_handle]
2579 _attrs = None
2580 _result = _execute.execute(b"IsBoostedTreesEnsembleInitialized", 1,
2581 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
2582 name=name)
2583 if _execute.must_record_gradient():
2584 _execute.record_gradient(
2585 "IsBoostedTreesEnsembleInitialized", _inputs_flat, _attrs, _result)
2586 _result, = _result
2587 return _result
2590def is_boosted_trees_quantile_stream_resource_initialized(quantile_stream_resource_handle, name=None):
2591 r"""Checks whether a quantile stream has been initialized.
2593 An Op that checks if quantile stream resource is initialized.
2595 Args:
2596 quantile_stream_resource_handle: A `Tensor` of type `resource`.
2597 resource; The reference to quantile stream resource handle.
2598 name: A name for the operation (optional).
2600 Returns:
2601 A `Tensor` of type `bool`.
2602 """
2603 _ctx = _context._context or _context.context()
2604 tld = _ctx._thread_local_data
2605 if tld.is_eager:
2606 try:
2607 _result = pywrap_tfe.TFE_Py_FastPathExecute(
2608 _ctx, "IsBoostedTreesQuantileStreamResourceInitialized", name,
2609 quantile_stream_resource_handle)
2610 return _result
2611 except _core._NotOkStatusException as e:
2612 _ops.raise_from_not_ok_status(e, name)
2613 except _core._FallbackException:
2614 pass
2615 try:
2616 return is_boosted_trees_quantile_stream_resource_initialized_eager_fallback(
2617 quantile_stream_resource_handle, name=name, ctx=_ctx)
2618 except _core._SymbolicException:
2619 pass # Add nodes to the TensorFlow graph.
2620 # Add nodes to the TensorFlow graph.
2621 _, _, _op, _outputs = _op_def_library._apply_op_helper(
2622 "IsBoostedTreesQuantileStreamResourceInitialized", quantile_stream_resource_handle=quantile_stream_resource_handle,
2623 name=name)
2624 _result = _outputs[:]
2625 if _execute.must_record_gradient():
2626 _attrs = ()
2627 _inputs_flat = _op.inputs
2628 _execute.record_gradient(
2629 "IsBoostedTreesQuantileStreamResourceInitialized", _inputs_flat, _attrs, _result)
2630 _result, = _result
2631 return _result
2633IsBoostedTreesQuantileStreamResourceInitialized = tf_export("raw_ops.IsBoostedTreesQuantileStreamResourceInitialized")(_ops.to_raw_op(is_boosted_trees_quantile_stream_resource_initialized))
2636def is_boosted_trees_quantile_stream_resource_initialized_eager_fallback(quantile_stream_resource_handle, name, ctx):
2637 quantile_stream_resource_handle = _ops.convert_to_tensor(quantile_stream_resource_handle, _dtypes.resource)
2638 _inputs_flat = [quantile_stream_resource_handle]
2639 _attrs = None
2640 _result = _execute.execute(b"IsBoostedTreesQuantileStreamResourceInitialized",
2641 1, inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
2642 name=name)
2643 if _execute.must_record_gradient():
2644 _execute.record_gradient(
2645 "IsBoostedTreesQuantileStreamResourceInitialized", _inputs_flat, _attrs, _result)
2646 _result, = _result
2647 return _result