Skip to content

[Relax][Frontend][TFLite] Add CUMSUM operator mapping#19434

Merged
tlopex merged 2 commits into
apache:mainfrom
Peruere1828:add-cumsum-mappings
Apr 24, 2026
Merged

[Relax][Frontend][TFLite] Add CUMSUM operator mapping#19434
tlopex merged 2 commits into
apache:mainfrom
Peruere1828:add-cumsum-mappings

Conversation

@Peruere1828

Copy link
Copy Markdown
Contributor

This commit adds frontend support for the TFLite CUMSUM operator by lowering it to relax.op.cumsum.

Specifically, it handles:

  • Extracting the axis parameter from a constant tensor and converting it to an integer.
  • Parsing the exclusive flag from CumsumOptions via FlatBuffers.
  • Deriving the target dtype from the output tensor.
  • Raising a NotImplementedError for the reverse flag as it is not yet supported by the Relax op.

Tracked in #19412.

This commit adds frontend support for the TFLite `CUMSUM` operator by
lowering it to `relax.op.cumsum`.

Specifically, it handles:
- Extracting the `axis` parameter from a constant tensor and converting it to an integer.
- Parsing the `exclusive` flag from `CumsumOptions` via FlatBuffers.
- Deriving the target `dtype` from the output tensor.
- Raising a `NotImplementedError` for the `reverse` flag as it is not yet supported by the Relax op.

Tracked in apache#19412.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for the TFLite CUMSUM operator to the Relax frontend, including the conversion logic and a test suite. The review feedback identifies two necessary improvements: implementing a check to prevent dynamic axis values which are currently unsupported, and adding a check for quantized inputs to prevent potential overflows or incorrect computations.

Comment thread python/tvm/relax/frontend/tflite/tflite_frontend.py
Comment thread python/tvm/relax/frontend/tflite/tflite_frontend.py
Comment thread python/tvm/relax/frontend/tflite/tflite_frontend.py
@Peruere1828

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements the CUMSUM operator in the TFLite to Relax frontend, including the conversion logic and a verification test case. The implementation supports basic cumulative sums but excludes support for quantization, dynamic axes, and reverse operations. A review comment suggests refactoring the axis extraction logic into a shared helper method to improve maintainability and reduce code duplication.

Comment on lines +1450 to +1453
axis = self.get_tensor_value(input_tensors[1])
if isinstance(axis, np.ndarray):
assert axis.size == 1, "only one value is expected."
axis = int(axis.flat[0])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic to extract the axis value from a numpy array is repeated in multiple places in this file. Consider creating a helper method to handle this extraction to improve maintainability.

@tlopex tlopex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tlopex tlopex merged commit 0b0afd8 into apache:main Apr 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants