|
496 | 496 | None)
|
497 | 497 | """,
|
498 | 498 | )
|
| 499 | + |
| 500 | +add_docs( |
| 501 | + torch.ops.fbgemm.block_bucketize_sparse_features_2d_weights, |
| 502 | + """ |
| 503 | +block_bucketize_sparse_features_2d_weights(lengths, indices, bucketize_pos, sequence, block_sizes, my_size, weights, weights_dim=1, batch_size_per_feature=None, max_B= -1, block_bucketize_pos=None, keep_orig_idx=False, total_num_blocks=None, keep_orig_idx_per_feature=None) -> Tuple[Tensor, Tensor, Optional[Tensor], Optional[Tensor], Optional[Tensor]] |
| 504 | +
|
| 505 | +Preprocess sparse features by partitioning sparse features into multiple |
| 506 | +buckets with support for 2D weights. Every feature is split into the same number of buckets, but the bucket |
| 507 | +sizes (widths) for the different features can be different. Moreover, the |
| 508 | +bucket sizes within each feature can be different. |
| 509 | +
|
| 510 | +This function is similar to block_bucketize_sparse_features but supports 2D weights, |
| 511 | +where each index can have multiple weight values associated with it. |
| 512 | +
|
| 513 | +Args: |
| 514 | + lengths (Tensor): The lengths of the sparse features. The tensor contains |
| 515 | + the lengths of each sample in a batch and each feature. Shape is `B * |
| 516 | + T` where `B` is the batch size and `T` is the number of features |
| 517 | +
|
| 518 | + indices (Tensor): The sparse data. Only support integer types. Shape is the |
| 519 | + sum of `lengths` |
| 520 | +
|
| 521 | + bucketize_pos (bool): If True, return the original relative indices within |
| 522 | + a sample. For example, `indices = [9, 8, 2, 1, 0, 8, 9]` and `lengths = |
| 523 | + [3, 4]`. The original relative indices within a sample for the indices |
| 524 | + are `[0, 1, 2, 0, 1, 2, 3]` |
| 525 | +
|
| 526 | + sequence (bool): If True, return the new indices positions in the original |
| 527 | + indices positions (the tensor is called `unbucketize_permute_data`). |
| 528 | +
|
| 529 | + block_sizes (Tensor): This tensor is used for the case where the bucket |
| 530 | + size within a feature is uniform (i.e., when |
| 531 | + `block_bucketize_pos=None`). The tensor contains bucket sizes (i.e., |
| 532 | + bucket widths) for each feature. `block_sizes[t]` represents the |
| 533 | + bucket size of feature `t`. Shape is the number of features. |
| 534 | +
|
| 535 | + my_size (int): The number of buckets for each feature. Note that every |
| 536 | + feature has the same number of buckets. |
| 537 | +
|
| 538 | + weights (Tensor): A float tensor that will be bucketized the same way as |
| 539 | + `indices`. This tensor must have shape `[indices.size(0), weights_dim]` |
| 540 | + where `weights_dim` is the dimension of the weight values for each index. |
| 541 | +
|
| 542 | + weights_dim (int = 1): The dimension of the weight values for each index. |
| 543 | + This parameter is only used when `weights` is not None. |
| 544 | +
|
| 545 | + batch_size_per_feature (Optional[Tensor] = None): An optional tensor that |
| 546 | + contains batch sizes for different features. If not None, batch sizes |
| 547 | + are not uniform among features. Otherwise, the operator will assume |
| 548 | + that the batch size is uniform and infer it from the `lengths` and |
| 549 | + `block_sizes` tensors |
| 550 | +
|
| 551 | + max_B (int = -1): The max batch size. Must be set if |
| 552 | + `batch_size_per_feature` is not None |
| 553 | +
|
| 554 | + block_bucketize_pos (Optional[List[Tensor]] = None): The input is used for |
| 555 | + non-uniform bucket sizes within a feature. `block_bucketize_pos` is a |
| 556 | + list of tensors. Each tensor contains the range offsets of buckets for |
| 557 | + each feature. These range offsets are equivalent to the complete |
| 558 | + cumulative sum of the bucket sizes. For example, `[0, 4, 20]` represents |
| 559 | + two buckets. The first bucket size is `(4 - 0) = 4`, and the second |
| 560 | + bucket size is `(20 - 4) = 16`. The length of `block_bucketize_pos` |
| 561 | + must be equal to the number of features. |
| 562 | +
|
| 563 | + keep_orig_idx (bool = False): If True, return original indices instead of |
| 564 | + the relative indices within each bucket |
| 565 | +
|
| 566 | + total_num_blocks (Optional[torch.Tensor] = None): An optional tensor that |
| 567 | + contains then number of logical buckets (aka blocks) within a given |
| 568 | + feature. This is useful for applications where the number of buckets |
| 569 | + is more than the number of physical GPUs, which is common in cases |
| 570 | + where we scale up/down the number of GPUs but want to maintain |
| 571 | + same numerical behavior. |
| 572 | +
|
| 573 | + keep_orig_idx_per_feature (Optional[Tensor] = None): An optional tensor that |
| 574 | + contains whether to keep original indices for each feature. If not None, |
| 575 | + the operator will use this tensor to determine whether to keep original |
| 576 | + indices for each feature. if None, will fallback to `keep_orig_idx` |
| 577 | +
|
| 578 | +Return: |
| 579 | + A tuple of tensors containing |
| 580 | +
|
| 581 | + (1) Bucketized lengths. Shape is `lengths.num() * my_size`. |
| 582 | +
|
| 583 | + (2) Bucketized indices. Same shape as `indices`. |
| 584 | +
|
| 585 | + (3) Bucketized weights or None if `weights` is None. Shape is |
| 586 | + `[indices.size(0), weights_dim]`. |
| 587 | +
|
| 588 | + (4) Bucketized positions or None if `bucketize_pos=False`. Same shape as |
| 589 | + `indices`. |
| 590 | +
|
| 591 | + (5) `unbucketize_permute` or None if `sequence=False`. Same shape as |
| 592 | + `indices` |
| 593 | +
|
| 594 | +**Example**: |
| 595 | +
|
| 596 | + >>> # Generate input example. Batch size = 2. Number of features = 4 |
| 597 | + >>> lengths = torch.tensor([0, 2, 1, 3, 2, 3, 3, 1], dtype=torch.int, device="cuda") |
| 598 | + >>> indices = torch.tensor([3, 4, 15, 11, 28, 29, 1, 10, 11, 12, 13, 11, 22, 20, 20], dtype=torch.int, device="cuda") |
| 599 | + >>> block_sizes = torch.tensor([[5, 15, 10, 20]], dtype=torch.int, device="cuda") |
| 600 | + >>> my_size = 2 # Number of buckets |
| 601 | + >>> weights_dim = 3 # Dimension of weight values for each index |
| 602 | + >>> weights = torch.randn(indices.size(0), weights_dim, dtype=torch.float, device="cuda") |
| 603 | + >>> # Invoke with keep_orig_idx=False, bucketize_pos=False, and |
| 604 | + >>> # sequence=False |
| 605 | + >>> torch.ops.fbgemm.block_bucketize_sparse_features_2d_weights( |
| 606 | + >>> lengths, |
| 607 | + >>> indices, |
| 608 | + >>> bucketize_pos=False, |
| 609 | + >>> sequence=False, |
| 610 | + >>> block_sizes=block_sizes, |
| 611 | + >>> my_size=my_size, |
| 612 | + >>> weights=weights, |
| 613 | + >>> weights_dim=weights_dim, |
| 614 | + >>> keep_orig_idx=False) |
| 615 | + """, |
| 616 | +) |
0 commit comments