Skip to content

[Fix][Relax][TFLite] Use astype for frontend casts#19932

Open
Aharrypotter wants to merge 1 commit into
apache:mainfrom
Aharrypotter:tflite-cast-api-fixes
Open

[Fix][Relax][TFLite] Use astype for frontend casts#19932
Aharrypotter wants to merge 1 commit into
apache:mainfrom
Aharrypotter:tflite-cast-api-fixes

Conversation

@Aharrypotter

Copy link
Copy Markdown
Contributor

Summary

Fix TFLite Relax frontend cast paths that still used removed/nonexistent cast
APIs.

  • Use relax.op.astype for FLOAT16 DEQUANTIZE constants.
  • Use relax.op.astype around the existing quantized AVERAGE_POOL_2D
    converter path.

Design

This PR only replaces invalid frontend API calls with relax.op.astype.

The quantized avgpool regression test calls the converter path directly because
the top-level TFLite importer still rejects quantized AVERAGE_POOL_2D before
conversion. Enabling that operator globally is out of scope.

Tests

Added:

  • test_dequantize_float16_uses_astype
  • test_quantized_avg_pool2d_uses_astype

Validated with:

python -m ruff format \
  python/tvm/relax/frontend/tflite/tflite_frontend.py \
  tests/python/relax/test_frontend_tflite.py

python -m ruff check \
  python/tvm/relax/frontend/tflite/tflite_frontend.py \
  tests/python/relax/test_frontend_tflite.py

python -m pytest \
  tests/python/relax/test_frontend_tflite.py \
  -k "dequantize or avg_pool" -q

Result:

ruff format: 2 files left unchanged
ruff check: All checks passed
targeted dequantize/avg_pool tests: 9 passed, 551 deselected

I also ran the full TFLite frontend file:

tests/python/relax/test_frontend_tflite.py: 559 passed, 1 failed

The remaining failure is unrelated to this PR:
test_broadcast_to expects R.multiply(..., ones) while the importer emits
R.broadcast_to(...).

@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 updates the TVM Relax TFLite frontend to use relax.op.astype instead of relax.op.cast (or relax.cast) for type casting in both convert_pool2d and convert_dequantize. Additionally, it introduces new unit tests to verify that R.astype is correctly generated for float16 dequantization and quantized average pooling. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

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.

1 participant