Repository navigation
[PyTorch Debug] Add max_blockwise_dynamic_range stats - #2137
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
d362d2a to
ae8d7bc
Compare
for more information, see https://pre-commit.ci
|
/te-ci pytorch |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
|
/te-ci pytorch |
|
/te-ci pytorch |
|
|
||
| tensor = tensor.abs().float() | ||
| if dims == 1: | ||
| tensor = tensor.reshape(-1, block_size) |
There was a problem hiding this comment.
This is slightly inaccurate view of the dynamic range - in the training, since we need both the value and its transpose, we should be looking at both the dynamic range of 1xblock_size tiles as well as block_sizex1, and I believe this only does the computation for the first case.
There was a problem hiding this comment.
That's true. I will take into account rowwise and columnwise for weight and activation and only rowwise for other tensors.
There was a problem hiding this comment.
When the gradient is used in dgrad and wgrad, both of its rowwise and columnwise data is needed. So should the gradient also need to be taken into account ?
| else: | ||
| # We want to have tensor of shape [nr_blocks, block_size, block_size], | ||
| # where each block is a block_size x block_size tile of the original tensor. | ||
| dim_x = tensor.shape[-2] // block_size |
There was a problem hiding this comment.
This should actually be a product of all dimensions other that -1 I think. Otherwise you basically create restriction that the dimension -2 has to be divisible by the block size.
There was a problem hiding this comment.
Greptile Overview
Greptile Summary
This PR introduces a new max_blockwise_dynamic_range statistic to TransformerEngine's PyTorch debug module, enabling analysis of quantization characteristics at block granularity. The feature extends the existing tensor statistics framework to accept dictionary-based stat configurations (in addition to strings), allowing users to specify custom block sizes and dimensionalities (1D or 2D) via YAML files. Three files are modified: (1) the stats computation module adds a new @torch.compile-decorated function that reshapes tensors into blocks, computes per-block max/min while excluding zeros, calculates log2-based dynamic ranges, and returns the maximum value; (2) the logging feature adds validation and parsing logic to handle the new dict-based stat format; (3) a comprehensive test validates correctness using synthetic tensors with known patterns. This integrates into the existing debug infrastructure (which already tracks metrics like overflows, MSE, and tensor-level dynamic range) by following the same registration pattern used for other statistics.
Important Files Changed
| Filename | Score | Overview |
|---|---|---|
| transformer_engine/debug/features/utils/stats_computation.py | 4/5 | Adds compute_max_blockwise_dynamic_range() function with 1D/2D block support, registration logic, and @torch.compile decorators for performance |
| transformer_engine/debug/features/log_tensor_stats.py | 4/5 | Extends stat specification format to accept dicts, adds validation/parsing methods for blockwise stats with parameter checking |
| tests/pytorch/debug/test_log.py | 5/5 | Adds comprehensive test with synthetic tensor patterns to validate blockwise dynamic range calculations and renames existing test for clarity |
Confidence score: 4/5
- This PR is safe to merge with only minor concerns about edge-case handling and code organization
- Score reflects solid implementation and thorough testing, but minor deductions for: (1) potential issues with malformed dict inputs in
_is_supported_stat()(lines 99-122 of log_tensor_stats.py) where nested key access could raise KeyError if "max_blockwise_dynamic_range" contains unexpected structure; (2) redundant validation work where_is_supported_stat()validates the same constraints that_parse_max_blockwise_dynamic_range_stats()assumes are already validated; (3) the 2D blocking logic (lines 63-68 of stats_computation.py) only computes block_size×block_size tiles along the trailing dimensions, which may not align with all use cases (as noted in previous reviews about transpose considerations) - Pay close attention to transformer_engine/debug/features/log_tensor_stats.py (validation logic for dict-based stats) and transformer_engine/debug/features/utils/stats_computation.py (2D block reshaping at lines 63-68)
Sequence Diagram
sequenceDiagram
participant User
participant debug_api
participant LogTensorStats
participant stats_computation
participant STATS_BUFFERS
participant Tensor
User->>debug_api: "initialize(config_file with max_blockwise_dynamic_range)"
debug_api->>LogTensorStats: "load config"
LogTensorStats->>LogTensorStats: "_is_supported_stat(max_blockwise_dynamic_range)"
LogTensorStats->>LogTensorStats: "_parse_max_blockwise_dynamic_range_stats()"
LogTensorStats->>stats_computation: "add_max_blockwise_dynamic_range_stats(block_size, dims)"
stats_computation->>stats_computation: "register stat in STATS dict"
stats_computation->>stats_computation: "register stat in stats_to_num"
stats_computation->>stats_computation: "register dependencies in DEPENDENCIES"
User->>debug_api: "inspect_tensor(layer_name, tensor_name, tensor)"
debug_api->>LogTensorStats: "inspect_tensor()"
LogTensorStats->>STATS_BUFFERS: "try_add_buffer(stats=[max_blockwise_dynamic_range_...])"
LogTensorStats->>STATS_BUFFERS: "feed(tensor)"
STATS_BUFFERS->>stats_computation: "compute_max_blockwise_dynamic_range(tensor, block_size, dims)"
stats_computation->>Tensor: "reshape based on dims"
stats_computation->>Tensor: "compute amax per block"
stats_computation->>Tensor: "compute amin per block (nonzero)"
stats_computation->>stats_computation: "calculate log2(amax) - log2(amin) per block"
stats_computation-->>STATS_BUFFERS: "return max dynamic range"
STATS_BUFFERS-->>LogTensorStats: "buffer updated"
User->>debug_api: "step()"
debug_api->>STATS_BUFFERS: "reduce and log stats"
STATS_BUFFERS->>stats_computation: "apply reduction function"
stats_computation-->>STATS_BUFFERS: "max across all buffers"
STATS_BUFFERS-->>debug_api: "aggregated stats"
debug_api-->>User: "stats logged to file"
3 files reviewed, 4 comments
|
|
||
|
|
||
| def test_log_stats_numerics(feature_dirs): | ||
| """Check corectness of dynamic range and max blockwise dynamic range stats""" |
There was a problem hiding this comment.
syntax: Typo: 'corectness' should be 'correctness'
| """Check corectness of dynamic range and max blockwise dynamic range stats""" | |
| """Check correctness of dynamic range and max blockwise dynamic range stats""" |
| def _is_supported_stat(self, stat: str | Dict): | ||
| """Returns True if the stat is supported by this feature, False otherwise.""" | ||
| if isinstance(stat, dict): | ||
| stat_name = list(stat.keys())[0] | ||
| if stat_name == "max_blockwise_dynamic_range": | ||
| stat_dict = stat[stat_name] | ||
| if not isinstance(stat_dict, dict): | ||
| return False | ||
| # Ensure only supported keys are present | ||
| allowed_keys = {"block_size", "dims"} | ||
| if any(k not in allowed_keys for k in stat_dict.keys()): | ||
| return False | ||
| block_size = stat_dict.get("block_size", 32) | ||
| dims = stat_dict.get("dims", 1) | ||
| # Type and value validation | ||
| if not isinstance(block_size, int) or not isinstance(dims, int): | ||
| return False | ||
| if block_size > 0 and dims in [1, 2]: | ||
| return True | ||
| return False | ||
| return stat in BaseLogTensorStats._get_supported_stats_list(None) | { | ||
| "cur_amax", | ||
| "dynamic_range", | ||
| } |
There was a problem hiding this comment.
style: _is_supported_stat doesn't handle the case where stat is a dict but stat_name is not "max_blockwise_dynamic_range". For example, if stat is {"unsupported_stat": {...}}, line 104 will evaluate to False and then fall through to line 118, returning False. However, if stat is {"max_blockwise_dynamic_range": "not_a_dict"}, line 105 returns False correctly. Consider explicitly handling unexpected dict keys by returning False early when stat_name != "max_blockwise_dynamic_range". Should this validation explicitly reject dicts with unknown stat names (e.g., raise an error) to make the failure mode clearer?
| if isinstance(stat, dict): | ||
| block_size = stat["max_blockwise_dynamic_range"].get("block_size", 32) | ||
| dims = stat["max_blockwise_dynamic_range"].get("dims", 1) | ||
| add_max_blockwise_dynamic_range_stats(block_size, dims) | ||
| parsed_stats.append( | ||
| f"max_blockwise_dynamic_range_block_size_{block_size}_dims_{dims}" | ||
| ) | ||
| else: | ||
| parsed_stats.append(stat) |
There was a problem hiding this comment.
logic: Direct dict key access stat["max_blockwise_dynamic_range"] will raise KeyError if stat is a dict but doesn't contain this key (e.g., {"other_key": {...}}). This contradicts the validation in _is_supported_stat which should have already filtered these out, but defensive programming suggests using .get() or re-validating the key existence here.
| for stat in config["stats"]: | ||
| assert ( | ||
| stat in self._get_supported_stats_list() | ||
| assert self._is_supported_stat( | ||
| stat | ||
| ), f"[NVTORCH INSPECT ERROR] Statistic {stat} is not supported." |
There was a problem hiding this comment.
style: Validation loop iterates over config["stats"] but then line 207 re-parses the same list. If config["stats"] is large, this is redundant work. Consider validating and parsing in a single pass, or storing the validation result.
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Greptile Overview
Greptile Summary
This review covers changes made since the last review, focusing on the addition of dual-orientation support for blockwise dynamic range statistics. The PR now computes max blockwise dynamic range for both rowwise and columnwise tensor layouts when analyzing activations and weights, addressing previous feedback about capturing transpose behavior. The implementation adds a both_orientations parameter that propagates from _parse_max_blockwise_dynamic_range_stats() (where it's determined from tensor_name) through to compute_max_blockwise_dynamic_range(), which conditionally computes stats for both orientations and returns the maximum. The test suite was expanded to parameterize over tensor types (activation/weight/gradient) and validate that dual-orientation logic produces expected results for synthetic test tensors with known structure. This enhancement fits into TransformerEngine's debug framework by providing more accurate quantization insights for tensors used in both forward and backward GEMM operations.
Important Files Changed
| Filename | Score | Overview |
|---|---|---|
| transformer_engine/debug/features/log_tensor_stats.py | 4/5 | Adds both_orientations flag computed from tensor_name; passes it to stat registration and encodes it in stat names |
| transformer_engine/debug/features/utils/stats_computation.py | 3/5 | Implements dual-orientation computation by optionally transposing tensors; refactors 2D blocking logic; creates very long stat names |
| tests/pytorch/debug/test_log.py | 3/5 | Parameterizes test over tensor types; validates dual-orientation behavior with synthetic tensors; expected value logic may be incorrect for 1D case when both_orientations=False |
Confidence score: 3/5
- This PR addresses previous feedback but introduces new complexity that requires careful validation; the dual-orientation logic should work correctly for the intended use case but edge cases remain
- Score reflects concerns about: (1) potential device/dtype issues when using Python's
max()on GPU tensors, (2) test validation logic that may not correctly reflect actual computation for non-dual-orientation cases, (3) lack of shape validation before flattening to 2D which could fail on 1D inputs, and (4) very long stat names that may impact usability - Pay close attention to transformer_engine/debug/features/utils/stats_computation.py lines 93-101 (device handling of max between two tensors) and tests/pytorch/debug/test_log.py lines 276-299 (expected value computation when
both_orientations=False)
3 files reviewed, 6 comments
| if both_orientations: | ||
| expected = math.log2(A) - math.log2(B) | ||
| else: | ||
| expected = 0 |
There was a problem hiding this comment.
logic: Logic issue: when both_orientations=False, this expects the max blockwise dynamic range (1D) to be 0. However, the tensor has row 0 with value A, rows 1-3 with value B, and remaining rows with epsilon. A 1D rowwise calculation should still find blocks containing row 0 (max A, min epsilon or B depending on block boundaries), yielding a non-zero dynamic range. The expected value of 0 only makes sense if the block size and data arrangement perfectly cancel out, which seems unlikely. For gradient tensors (single orientation), why should the 1D max blockwise dynamic range be 0 when row 0 contains large value A? Shouldn't blocks containing row 0 still produce a non-zero dynamic range?
| for line in output.splitlines(): | ||
| if ( | ||
| f"max_blockwise_dynamic_range_block_size_4_dims_1_both_orientations_{both_orientations}" | ||
| in line | ||
| ): | ||
| max_blockwise_dynamic_range_block_size_4_dims_1 = float(line.split("value=")[1]) | ||
| if both_orientations: | ||
| expected = math.log2(A) - math.log2(B) | ||
| else: | ||
| expected = 0 | ||
| assert max_blockwise_dynamic_range_block_size_4_dims_1 == pytest.approx( | ||
| expected, abs=1e-4 | ||
| ) | ||
| elif ( | ||
| f"max_blockwise_dynamic_range_block_size_4_dims_2_both_orientations_{both_orientations}" | ||
| in line | ||
| ): | ||
| max_blockwise_dynamic_range_block_size_4_dims_2 = float(line.split("value=")[1]) | ||
|
|
||
| expected = math.log2(A) - math.log2(B) | ||
| assert max_blockwise_dynamic_range_block_size_4_dims_2 == pytest.approx( | ||
| expected, abs=1e-4 | ||
| ) | ||
| elif "dynamic_range" in line and "max_blockwise" not in line: | ||
| dynamic_range = float(line.split("value=")[1]) | ||
| expected = math.log2(A) - math.log2(epsilon) | ||
| assert dynamic_range == pytest.approx(expected, abs=1e-4) |
There was a problem hiding this comment.
style: The test constructs a tensor with rows [0]=A, [1:4]=B, rest=epsilon, but only validates that certain stats match expected values. Consider explicitly asserting that all three expected stats (dims_1, dims_2, dynamic_range) are found in the output, otherwise the test silently passes if a stat is missing from the log.
| assert max_blockwise_dynamic_range_block_size_4_dims_2 == pytest.approx( | ||
| expected, abs=1e-4 | ||
| ) | ||
| elif "dynamic_range" in line and "max_blockwise" not in line: |
There was a problem hiding this comment.
style: The condition "dynamic_range" in line and "max_blockwise" not in line is fragile—if a future stat name includes "dynamic_range" as a substring but isn't the global dynamic_range, this will incorrectly match. Consider using a more precise identifier (e.g., check for an exact stat key in the log format).
| # Flatten to 2D: [batch, seq, hidden, ...] -> [batch*seq*..., hidden] | ||
| tensor_2d = tensor.reshape(-1, tensor.shape[-1]) |
There was a problem hiding this comment.
logic: Flattening assumes the last dimension is 'hidden', but this isn't validated. If a tensor has shape [batch] (1D), this will fail. Add a check that tensor.ndim >= 1 or document the expected input shape. Does this function expect only multi-dimensional tensors where the last dimension is 'hidden', or should 1D tensors be explicitly handled or rejected?
| block_size: int, dims: int, both_orientations: bool = False | ||
| ): | ||
| """Register max_blockwise_X_dynamic_range stats for the recipe.""" | ||
| stat_name = f"max_blockwise_dynamic_range_block_size_{block_size}_dims_{dims}_both_orientations_{both_orientations}" |
There was a problem hiding this comment.
style: Stat name grows very long with the added suffix. Consider abbreviating 'both_orientations' to 'both_orient' or use a shorter flag like 'bidir' to keep YAML keys and log output readable.
There was a problem hiding this comment.
Greptile Overview
Greptile Summary
This review covers only the changes made since the last review, not the entire PR.
The latest changes include minor formatting fixes to the test file (test_log.py) to enforce the 100-character line limit by wrapping long f-string conditionals. No functional logic was altered—these are purely style adjustments to pass pre-commit linting checks. The changes align with the project's Black formatter configuration (.pre-commit-config.yaml) and column-limit settings in .clang-format and pyproject.toml. The trailing whitespace removal on line 239 is a standard cleanup enforced by the trailing-whitespace hook.
Important Files Changed
| Filename | Score | Overview |
|---|---|---|
| tests/pytorch/debug/test_log.py | 5/5 | Non-functional formatting changes: wrapped long f-string conditionals to respect 100-char limit and removed trailing whitespace. |
| transformer_engine/debug/features/utils/stats_computation.py | 3/5 | Added compute_max_blockwise_dynamic_range function and registration logic; uses Python max() on tensors (line 96) which forces device synchronization. |
| transformer_engine/debug/features/log_tensor_stats.py | 3.5/5 | Extended validation and parsing for dict-typed max_blockwise_dynamic_range stats; hardcoded tensor name check for both_orientations may fail silently with new tensor types. |
Confidence score: 4/5
- This PR is safe to merge with minimal risk, though attention should be paid to the performance implications of the
max()call in the stats computation. - Score reflects minor performance and maintainability concerns: the Python
max()on tensors (line 96 instats_computation.py) causes device synchronization in training loops, and the hardcoded tensor name check forboth_orientations(line 136 inlog_tensor_stats.py) reduces extensibility. The test file changes are purely cosmetic. - Pay close attention to
transformer_engine/debug/features/utils/stats_computation.pylines 96-100, where themax()call may degrade performance in tight training loops.
3 files reviewed, no comments
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Greptile Overview
Greptile Summary
This PR adds support for computing and logging max_blockwise_dynamic_range statistics in the TransformerEngine debug framework. The feature calculates the maximum dynamic range (log2 of max/min ratio) across blocks within tensors, supporting both 1D (consecutive elements) and 2D (tile-based) block configurations.
Key changes:
- Introduces
BlockwiseDynamicRangeStatnamedtuple to represent blockwise stat configurations with block_size, dims, and orientation settings - Implements
compute_max_blockwise_dynamic_range()function that flattens tensors to 2D and computes per-block dynamic ranges, optionally considering both rowwise and columnwise orientations - For activation/weight tensors, computes both orientations and returns the maximum (capturing worst-case quantization impact)
- For gradient tensors, computes only rowwise orientation
- Extends YAML configuration to accept dict-based stat specs:
max_blockwise_dynamic_range: {block_size: 32, dims: 1} - Adds validation logic to ensure only valid configurations are accepted
- Includes comprehensive test coverage with both integration tests and direct unit tests
Confidence Score: 4/5
- This PR is safe to merge with minor style considerations already noted in previous comments
- The implementation is well-structured with proper validation, comprehensive tests, and correct mathematical logic. Previous comments have already identified the key areas for improvement (style suggestions, validation edge cases). The core functionality correctly handles tensor flattening, block-based computation, and dual-orientation support. Test coverage is thorough with both integration and unit tests validating expected behavior across multiple scenarios.
- No files require special attention - all previously identified issues are style/documentation improvements rather than functional bugs
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| transformer_engine/debug/features/utils/stats_computation.py | 4/5 | Adds compute_max_blockwise_dynamic_range function and BlockwiseDynamicRangeStat namedtuple for computing maximum dynamic range across tensor blocks. Implementation handles 1D/2D blocks and dual orientation support correctly. |
| transformer_engine/debug/features/log_tensor_stats.py | 4/5 | Adds validation and parsing logic for max_blockwise_dynamic_range stat configuration. Properly validates dict-based stat configs and converts them to namedtuples before registration. |
| tests/pytorch/debug/test_log.py | 4/5 | Adds comprehensive tests for max_blockwise_dynamic_range stat including integration tests via logging framework and direct unit tests. Tests cover multiple orientations, block sizes, and edge cases. |
Sequence Diagram
sequenceDiagram
participant User
participant LogTensorStats
participant StatsBuffer
participant StatsComputation
participant MetricLogger
User->>LogTensorStats: Configure stats in YAML<br/>(max_blockwise_dynamic_range with block_size, dims)
User->>LogTensorStats: inspect_tensor(tensor, tensor_name, ...)
LogTensorStats->>LogTensorStats: _is_supported_stat(stat_dict)
Note over LogTensorStats: Validates dict has "max_blockwise_dynamic_range" key<br/>and valid block_size, dims parameters
LogTensorStats->>LogTensorStats: _parse_max_blockwise_dynamic_range_stats(stats, tensor_name)
Note over LogTensorStats: Determines max_over_orientations based on tensor_name<br/>(True for activation/weight, False for gradient)
LogTensorStats->>StatsComputation: add_max_blockwise_dynamic_range_stats(block_size, dims, max_over_orientations)
Note over StatsComputation: Creates BlockwiseDynamicRangeStat namedtuple<br/>Registers compute and combiner functions in STATS dict
StatsComputation-->>LogTensorStats: Returns BlockwiseDynamicRangeStat namedtuple
LogTensorStats->>StatsBuffer: try_add_buffer(layer_name, tensor_name, stats, ...)
Note over StatsBuffer: Registers buffer for collecting stats
User->>User: Training step occurs
User->>StatsBuffer: collect_stats(tensor)
StatsBuffer->>StatsComputation: compute_max_blockwise_dynamic_range(tensor, stat_config)
alt max_over_orientations == True
StatsComputation->>StatsComputation: _compute_for_one_orientation(tensor_2d)
Note over StatsComputation: Computes rowwise dynamic range
StatsComputation->>StatsComputation: _compute_for_one_orientation(tensor_2d.T)
Note over StatsComputation: Computes columnwise dynamic range
StatsComputation->>StatsComputation: max(rowwise, columnwise)
else max_over_orientations == False
StatsComputation->>StatsComputation: _compute_for_one_orientation(tensor_2d)
Note over StatsComputation: Computes rowwise dynamic range only
end
StatsComputation-->>StatsBuffer: Returns max blockwise dynamic range value
User->>StatsBuffer: flush_buffers()
StatsBuffer->>StatsBuffer: str(stat_namedtuple)
Note over StatsBuffer: Converts BlockwiseDynamicRangeStat to string:<br/>"max_blockwise_dynamic_range_block_size_X_dims_Y[_max_over_orientations]"
StatsBuffer->>MetricLogger: log_scalar(stat_name_str, stat_value, iteration)
MetricLogger-->>User: Logs stat to output file
4 files reviewed, no comments
There was a problem hiding this comment.
Greptile Overview
Greptile Summary
This PR adds a new max_blockwise_dynamic_range statistic to compute the maximum dynamic range (log2(max/min)) across blocks within tensors during debugging.
Key changes:
- Introduces
BlockwiseDynamicRangeStatnamed tuple to represent stat configurations withblock_size,dims(1D or 2D blocks), andmax_over_orientationsparameters - Implements
compute_max_blockwise_dynamic_range()that flattens tensors to 2D, computes per-block dynamic ranges, and optionally takes max over both rowwise/columnwise orientations for activation/weight tensors - Extends
LogTensorStatsfeature with dict-based stat configuration support and validation logic for the new stat type - Adds comprehensive test coverage including integration tests with debug sessions and direct unit tests for edge cases
Implementation highlights:
- Handles zero-only blocks correctly by returning 0 dynamic range
- Uses
masked_fillwith inf to compute min over non-zero elements - For 2D blocks, reshapes tensors into block_size × block_size tiles using permute operations
- Different tensor types use different orientations: activation/weight compute max over both orientations, gradient/dgrad use single orientation
Confidence Score: 5/5
- This PR is safe to merge with no identified issues
- The implementation is well-designed with proper validation, correct mathematical logic for computing blockwise dynamic ranges, comprehensive edge case handling (zero blocks, different orientations, 1D/2D blocks), and thorough test coverage including both integration and unit tests. All previous review comments have been addressed or were based on misunderstandings of the code logic.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| transformer_engine/debug/features/utils/stats_computation.py | 5/5 | Adds compute_max_blockwise_dynamic_range function and BlockwiseDynamicRangeStat named tuple to compute maximum dynamic range across tensor blocks. Handles 1D/2D blocks, zero blocks, and multi-orientation computation correctly. |
| transformer_engine/debug/features/log_tensor_stats.py | 5/5 | Integrates max_blockwise_dynamic_range stat with validation (_is_supported_stat) and parsing (_parse_max_blockwise_dynamic_range_stats) logic. Correctly handles dict-based stat configs and determines orientation based on tensor type. |
| transformer_engine/debug/features/utils/stats_buffer.py | 5/5 | Minor change to convert stat keys to strings for logging using str(), supporting both string stats and BlockwiseDynamicRangeStat named tuples. |
| tests/pytorch/debug/test_log.py | 5/5 | Adds comprehensive tests for max_blockwise_dynamic_range: integration test (test_log_stats_numerics) validates stats in debug session for different tensor types, and unit test (test_compute_max_blockwise_dynamic_range_direct) covers edge cases including block sizes, orientations, and 3D tensors. |
Sequence Diagram
sequenceDiagram
participant User
participant DebugAPI as debug_api
participant LogTensorStats
participant StatsBuffer as STATS_BUFFERS
participant StatsComp as stats_computation
User->>DebugAPI: initialize(config_file)
Note over LogTensorStats: Config specifies max_blockwise_dynamic_range<br/>with block_size, dims parameters
User->>DebugAPI: inspect_tensor(tensor, tensor_name)
DebugAPI->>LogTensorStats: inspect_tensor_enabled()
LogTensorStats-->>DebugAPI: run_current, next_iter
alt Feature enabled for this iteration
DebugAPI->>LogTensorStats: inspect_tensor(config, tensor)
LogTensorStats->>LogTensorStats: _is_supported_stat(stat)
Note over LogTensorStats: Validates dict-based stat config<br/>with allowed keys and values
LogTensorStats->>LogTensorStats: _parse_max_blockwise_dynamic_range_stats()
Note over LogTensorStats: Converts dict to BlockwiseDynamicRangeStat<br/>named tuple, sets max_over_orientations<br/>based on tensor_name
LogTensorStats->>StatsBuffer: try_add_buffer(stats)
LogTensorStats->>StatsBuffer: feed(tensor)
StatsBuffer->>StatsComp: compute_max_blockwise_dynamic_range(tensor, stat_config)
StatsComp->>StatsComp: Flatten tensor to 2D
alt max_over_orientations = True
StatsComp->>StatsComp: _compute_for_one_orientation(rowwise)
StatsComp->>StatsComp: _compute_for_one_orientation(columnwise)
StatsComp->>StatsComp: max(rowwise, columnwise)
else max_over_orientations = False
StatsComp->>StatsComp: _compute_for_one_orientation(rowwise)
end
Note over StatsComp: For each block: compute log2(amax) - log2(amin_nonzero)<br/>Return max across all blocks
StatsComp-->>StatsBuffer: dynamic_range_value
StatsBuffer-->>LogTensorStats: stored
end
User->>DebugAPI: step()
DebugAPI->>StatsBuffer: gather_and_log()
StatsBuffer->>StatsBuffer: str(stat_name) for logging
StatsBuffer->>User: Log to file with metric name
4 files reviewed, no comments
There was a problem hiding this comment.
Greptile Overview
Greptile Summary
This PR introduces max_blockwise_dynamic_range statistics to the PyTorch debug logging system. The implementation computes the maximum dynamic range (log2 of max/min ratio) across blocks within tensors, supporting both 1D (consecutive elements) and 2D (tile-based) block configurations.
Key additions:
BlockwiseDynamicRangeStatnamedtuple to represent stat configurations with block_size, dims, and max_over_orientationscompute_max_blockwise_dynamic_range()function that flattens tensors to 2D and computes blockwise dynamic ranges, optionally checking both rowwise and columnwise orientations for activations/weights- Registration logic via
add_max_blockwise_dynamic_range_stats()that integrates with existing stats computation framework - Integration with YAML configuration parsing in
log_tensor_stats.py - Comprehensive test coverage verifying correctness for different tensor types and orientations
The implementation correctly handles the computational logic: for activations/weights it computes max over both orientations (capturing worst-case GEMM behavior), while gradients use single orientation only. The code properly masks zero values when computing min, preventing log2(0) errors.
Confidence Score: 4/5
- This PR is safe to merge with minor style improvements recommended
- The implementation is functionally correct with proper handling of edge cases (zero blocks, 1D/2D configurations). The test coverage validates the mathematical correctness. One minor style issue exists at line 116 using Python's built-in max() instead of torch.max() for comparing scalar tensors, but this works correctly. The code integrates cleanly with the existing statistics framework and follows established patterns.
- No files require special attention - the implementation is solid with only minor style improvements recommended
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| transformer_engine/debug/features/utils/stats_computation.py | 4/5 | Adds BlockwiseDynamicRangeStat namedtuple, compute_max_blockwise_dynamic_range function, and registration logic for blockwise dynamic range statistics. Implementation handles 1D/2D blocks with optional dual-orientation computation. Minor style improvement possible for Python max() usage. |
Sequence Diagram
sequenceDiagram
participant User as User/Config
participant LogTensorStats as LogTensorStats
participant StatsBuffer as StatsBuffer
participant StatsComp as stats_computation
participant PyTorch as PyTorch Backend
User->>LogTensorStats: Configure max_blockwise_dynamic_range in YAML
Note over User,LogTensorStats: {block_size: 4, dims: 1/2}
LogTensorStats->>LogTensorStats: _is_supported_stat(stat)
Note over LogTensorStats: Validates dict structure,<br/>block_size > 0, dims in [1,2]
LogTensorStats->>LogTensorStats: _parse_max_blockwise_dynamic_range_stats()
Note over LogTensorStats: Determines max_over_orientations<br/>based on tensor_name
LogTensorStats->>StatsComp: add_max_blockwise_dynamic_range_stats(block_size, dims, max_over_orientations)
StatsComp->>StatsComp: Create BlockwiseDynamicRangeStat named tuple
Note over StatsComp: Register in stats_to_num, DEPENDENCIES, STATS
StatsComp-->>LogTensorStats: Return stat_key (named tuple)
LogTensorStats->>StatsBuffer: try_add_buffer(stats=[stat_key, ...])
StatsBuffer->>StatsBuffer: Initialize buffer for layer/tensor
LogTensorStats->>StatsBuffer: feed(tensor)
StatsBuffer->>StatsComp: Compute stat via lambda in STATS dict
StatsComp->>StatsComp: compute_max_blockwise_dynamic_range(tensor, stat_config)
alt max_over_orientations=True
StatsComp->>StatsComp: _compute_for_one_orientation(tensor_2d)
StatsComp->>PyTorch: Reshape, amax/amin, log2
PyTorch-->>StatsComp: rowwise_result
StatsComp->>StatsComp: _compute_for_one_orientation(tensor_2d.T)
StatsComp->>PyTorch: Reshape, amax/amin, log2
PyTorch-->>StatsComp: columnwise_result
StatsComp->>StatsComp: max(rowwise_result, columnwise_result)
else max_over_orientations=False
StatsComp->>StatsComp: _compute_for_one_orientation(tensor_2d)
StatsComp->>PyTorch: Reshape, amax/amin, log2
PyTorch-->>StatsComp: result
end
StatsComp-->>StatsBuffer: Return max blockwise dynamic range
StatsBuffer->>StatsBuffer: Store in buffer
StatsBuffer->>StatsBuffer: log_stats()
StatsBuffer->>StatsBuffer: Apply combiner (max over buffers)
StatsBuffer->>StatsBuffer: str(stat_key) via __str__()
Note over StatsBuffer: Converts to:<br/>max_blockwise_dynamic_range_<br/>block_size_N_dims_M[_max_over_orientations]
StatsBuffer->>User: Log metric to output
1 file reviewed, 1 comment
| return max( | ||
| _compute_for_one_orientation(tensor_2d), # Rowwise orientation | ||
| _compute_for_one_orientation(tensor_2d.transpose(-2, -1)), # Columnwise orientation | ||
| ) |
There was a problem hiding this comment.
style: Python's built-in max() works here but torch.max() would be more explicit for comparing scalar tensors and ensures proper device handling
| return max( | |
| _compute_for_one_orientation(tensor_2d), # Rowwise orientation | |
| _compute_for_one_orientation(tensor_2d.transpose(-2, -1)), # Columnwise orientation | |
| ) | |
| return torch.max( | |
| _compute_for_one_orientation(tensor_2d), # Rowwise orientation | |
| _compute_for_one_orientation(tensor_2d.transpose(-2, -1)), # Columnwise orientation | |
| ) |
|
/te-ci pytorch |
* code drop Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixes Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> --------- Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com>
* [Common] Deleted unused header (#2324) Deleted unused header Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [JAX] L1_jax_distributed_test suit with individual executions (#2321) * L1 rework Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com> * comment out test_multi_process_grouped_gemm for now Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com> * rm e5m2 from test norm + MXFP8 Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com> --------- Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * for branch Signed-off-by: Peter Dykas <wdykas@nvidia.com> * clean up and tests Signed-off-by: Peter Dykas <wdykas@nvidia.com> * change tests Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [PyTorch debug] Fixes to debug tests failures (#2268) * code drop Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix: Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> --------- Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [PyTorch Debug] Add max_blockwise_dynamic_range stats (#2137) * code drop Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixes Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> --------- Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [JAX] Fix bug with pre scale bias (#2300) * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> --------- Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [JAX] Try to use pre-downloaded dataset artifacts first (#2345) * Try to use pre-downloaded dataset artifacts first Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com> * Set HF_HUB_OFFLINE to disable any network calls to HF when the pre-downloaded dataset is available Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com> --------- Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * Fix out of bounds access in the FP4 dequantize kernel (#2346) Signed-off-by: Przemek Tredak <ptredak@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * Make FP8 weights compatible with older MCore version (#2342) * Make cast_master_weights_to_fp8 compatible with older MCore version Signed-off-by: kunlunl <kunlunl@nvidia.com> * Rename keep_columnwise to manual_post_all_gather_processing & Optimize unit test Signed-off-by: kunlunl <kunlunl@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove redundant _test_mini_optimizer() Signed-off-by: kunlunl <kunlunl@nvidia.com> --------- Signed-off-by: kunlunl <kunlunl@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tim Moon <4406448+timmoon10@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [JAX] Add test to check jaxpr that amax is reused for nvfp4 recipe (#2348) * Add test to check jaxpr that amax is reused for nvfp4 recipe Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com> * Move test to test_helper.py and rename file Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * Fix sharding of segment position to match id in ring attention. (#2349) Signed-off-by: Peter Dykas <wdykas@nvidia.com> * Disable cuDNN attention for known IMA and NaNs (#2344) * Fix cuDNN backend selection for more case. Add CG as a option as well Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> * fix logic Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> * Fix cuDNN checks Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> * Add more checks Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> * Fix cuddn version Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> * Fix error message Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> * Add check for window size Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> --------- Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [JAX] Default to fused attention in JAX DPA (#2363) * Default to fused attention in JAX DPA Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com> * Consolidate documentation for DPA in JAX Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Signed-off-by: Kshitij Lakhani <33047503+KshitijLakhani@users.noreply.github.com> * Correctly update the documentation for defaults in JAX DPA Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Signed-off-by: Kshitij Lakhani <33047503+KshitijLakhani@users.noreply.github.com> --------- Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com> Signed-off-by: Kshitij Lakhani <33047503+KshitijLakhani@users.noreply.github.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * Update cudnn frontend to v1.16.0 (#2362) Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [common] Remove kvpacked and qkvpacked attention functions for every kernel type. (#2287) * code drop Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * depracted compile time warning + \warning -> \deprecated Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * Move Triton to common (#2359) * move triton to common and change paths Signed-off-by: tdophung <tdophung@nvidia.com> * Formatting Signed-off-by: tdophung <tdophung@nvidia.com> --------- Signed-off-by: tdophung <tdophung@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [JAX] Fused layers argument default values changed (#2347) * Changing default activations in MLP, TransformerLayer, dropout rate after FC1 to 0, and return_layernorm_output to False Signed-off-by: tdophung <tdophung@nvidia.com> * Fixing the failing tests by hard coding arguments to the previous values instead of relying on newer default values Signed-off-by: tdophung <tdophung@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: tdophung <tdophung@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * remove comment from gpt Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * minor changes for num_splits logic Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * replace None with 1 as default Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix last commit Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * fix docstring Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * fix dtype in pack/unpack when FP8 Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * add fused_attn_supported constraint for some tests Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * update FA3 installation commands Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * update FA3 installation commands in DPA Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * separate fused fp8 and f16 flags in tests Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * initialize fused_attn_supported_f16 Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * fix FA installation in L3 tests Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> --------- Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com> Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com> Signed-off-by: Przemek Tredak <ptredak@nvidia.com> Signed-off-by: kunlunl <kunlunl@nvidia.com> Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com> Signed-off-by: Kshitij Lakhani <33047503+KshitijLakhani@users.noreply.github.com> Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> Signed-off-by: tdophung <tdophung@nvidia.com> Co-authored-by: Oleg Goncharov <64355998+Oleg-Goncharov@users.noreply.github.com> Co-authored-by: Phuong Nguyen <phuonguyen@nvidia.com> Co-authored-by: root <root@gpu-h100-0496.cm.cluster> Co-authored-by: Peter Dykas <wdykas@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Paweł Gadziński <62263673+pggPL@users.noreply.github.com> Co-authored-by: jberchtold-nvidia <158520091+jberchtold-nvidia@users.noreply.github.com> Co-authored-by: Przemyslaw Tredak <ptredak@nvidia.com> Co-authored-by: Kunlun Li <94586211+kunlunl@users.noreply.github.com> Co-authored-by: Tim Moon <4406448+timmoon10@users.noreply.github.com> Co-authored-by: Michael Goldfarb <mgoldfarb@nvidia.com> Co-authored-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> Co-authored-by: Kshitij Lakhani <33047503+KshitijLakhani@users.noreply.github.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: Teddy Do <tdophung@nvidia.com> Co-authored-by: wdykas <73254672+wdykas@users.noreply.github.com>
* [Common] Deleted unused header (#2324) Deleted unused header Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [JAX] L1_jax_distributed_test suit with individual executions (#2321) * L1 rework Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com> * comment out test_multi_process_grouped_gemm for now Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com> * rm e5m2 from test norm + MXFP8 Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com> --------- Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * for branch Signed-off-by: Peter Dykas <wdykas@nvidia.com> * clean up and tests Signed-off-by: Peter Dykas <wdykas@nvidia.com> * change tests Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [PyTorch debug] Fixes to debug tests failures (#2268) * code drop Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix: Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> --------- Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [PyTorch Debug] Add max_blockwise_dynamic_range stats (#2137) * code drop Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixes Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> --------- Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [JAX] Fix bug with pre scale bias (#2300) * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> --------- Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [JAX] Try to use pre-downloaded dataset artifacts first (#2345) * Try to use pre-downloaded dataset artifacts first Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com> * Set HF_HUB_OFFLINE to disable any network calls to HF when the pre-downloaded dataset is available Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com> --------- Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * Fix out of bounds access in the FP4 dequantize kernel (#2346) Signed-off-by: Przemek Tredak <ptredak@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * Make FP8 weights compatible with older MCore version (#2342) * Make cast_master_weights_to_fp8 compatible with older MCore version Signed-off-by: kunlunl <kunlunl@nvidia.com> * Rename keep_columnwise to manual_post_all_gather_processing & Optimize unit test Signed-off-by: kunlunl <kunlunl@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove redundant _test_mini_optimizer() Signed-off-by: kunlunl <kunlunl@nvidia.com> --------- Signed-off-by: kunlunl <kunlunl@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tim Moon <4406448+timmoon10@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [JAX] Add test to check jaxpr that amax is reused for nvfp4 recipe (#2348) * Add test to check jaxpr that amax is reused for nvfp4 recipe Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com> * Move test to test_helper.py and rename file Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * Fix sharding of segment position to match id in ring attention. (#2349) Signed-off-by: Peter Dykas <wdykas@nvidia.com> * Disable cuDNN attention for known IMA and NaNs (#2344) * Fix cuDNN backend selection for more case. Add CG as a option as well Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> * fix logic Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> * Fix cuDNN checks Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> * Add more checks Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> * Fix cuddn version Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> * Fix error message Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> * Add check for window size Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> --------- Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [JAX] Default to fused attention in JAX DPA (#2363) * Default to fused attention in JAX DPA Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com> * Consolidate documentation for DPA in JAX Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Signed-off-by: Kshitij Lakhani <33047503+KshitijLakhani@users.noreply.github.com> * Correctly update the documentation for defaults in JAX DPA Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Signed-off-by: Kshitij Lakhani <33047503+KshitijLakhani@users.noreply.github.com> --------- Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com> Signed-off-by: Kshitij Lakhani <33047503+KshitijLakhani@users.noreply.github.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * Update cudnn frontend to v1.16.0 (#2362) Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [common] Remove kvpacked and qkvpacked attention functions for every kernel type. (#2287) * code drop Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * depracted compile time warning + \warning -> \deprecated Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * Move Triton to common (#2359) * move triton to common and change paths Signed-off-by: tdophung <tdophung@nvidia.com> * Formatting Signed-off-by: tdophung <tdophung@nvidia.com> --------- Signed-off-by: tdophung <tdophung@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [JAX] Fused layers argument default values changed (#2347) * Changing default activations in MLP, TransformerLayer, dropout rate after FC1 to 0, and return_layernorm_output to False Signed-off-by: tdophung <tdophung@nvidia.com> * Fixing the failing tests by hard coding arguments to the previous values instead of relying on newer default values Signed-off-by: tdophung <tdophung@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: tdophung <tdophung@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> * remove comment from gpt Signed-off-by: Peter Dykas <wdykas@nvidia.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * minor changes for num_splits logic Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * replace None with 1 as default Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix last commit Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * fix docstring Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * fix dtype in pack/unpack when FP8 Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * add fused_attn_supported constraint for some tests Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * update FA3 installation commands Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * update FA3 installation commands in DPA Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * separate fused fp8 and f16 flags in tests Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * initialize fused_attn_supported_f16 Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> * fix FA installation in L3 tests Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> --------- Signed-off-by: Oleg Goncharov <ogoncharov@nvidia.com> Signed-off-by: Peter Dykas <wdykas@nvidia.com> Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com> Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com> Signed-off-by: Przemek Tredak <ptredak@nvidia.com> Signed-off-by: kunlunl <kunlunl@nvidia.com> Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com> Signed-off-by: Kshitij Lakhani <33047503+KshitijLakhani@users.noreply.github.com> Signed-off-by: Charlene Yang <8636796+cyanguwa@users.noreply.github.com> Signed-off-by: tdophung <tdophung@nvidia.com> Co-authored-by: Oleg Goncharov <64355998+Oleg-Goncharov@users.noreply.github.com> Co-authored-by: Phuong Nguyen <phuonguyen@nvidia.com> Co-authored-by: root <root@gpu-h100-0496.cm.cluster> Co-authored-by: Peter Dykas <wdykas@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Paweł Gadziński <62263673+pggPL@users.noreply.github.com> Co-authored-by: jberchtold-nvidia <158520091+jberchtold-nvidia@users.noreply.github.com> Co-authored-by: Przemyslaw Tredak <ptredak@nvidia.com> Co-authored-by: Kunlun Li <94586211+kunlunl@users.noreply.github.com> Co-authored-by: Tim Moon <4406448+timmoon10@users.noreply.github.com> Co-authored-by: Michael Goldfarb <mgoldfarb@nvidia.com> Co-authored-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> Co-authored-by: Kshitij Lakhani <33047503+KshitijLakhani@users.noreply.github.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: Teddy Do <tdophung@nvidia.com> Co-authored-by: wdykas <73254672+wdykas@users.noreply.github.com>
Description
The
max_blockwise_dynamic_rangestats computes and returns the maximum value among the dynamic ranges calculated for each individual block within a tensor. Block size and dimensionality(1 or 2) can be specified in .yaml file.Type of change
Checklist: