Skip to content

fix(HuggingFace): drop unused TensorFlow import in sentiment analysis codegen - #6809

Merged
xuang7 merged 6 commits into
apache:mainfrom
Nicoleee1108:fix/hf-sentiment-unused-tf-import-6794
Aug 5, 2026
Merged

fix(HuggingFace): drop unused TensorFlow import in sentiment analysis codegen#6809
xuang7 merged 6 commits into
apache:mainfrom
Nicoleee1108:fix/hf-sentiment-unused-tf-import-6794

Conversation

@kz930

@kz930 kz930 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

HuggingFaceSentimentAnalysisOpDesc.generatePythonCode emitted an import for TFAutoModelForSequenceClassification that the generated body never uses — the model is loaded through the PyTorch AutoModelForSequenceClassification.

The symbol does not exist in the pinned transformers: the library dropped its TensorFlow backend in 5.0, and amber/operator-requirements.txt has been on 5.x since #5016 (5.5.0 today). So the import is not dead weight — it raises ImportError at module load and takes the whole generated script down before any inference runs, on every environment that installs the pinned requirements.

Fix — remove the unused import:

 from transformers import pipeline
 from transformers import AutoModelForSequenceClassification
-from transformers import TFAutoModelForSequenceClassification
 from transformers import AutoTokenizer, AutoConfig

Any related issues, documentation, discussions?

Closes #6794

How was this PR tested?

Manually, per @Yicong-Huang's request: the existing spec asserts on the emitted text and py_compile only parses it, so neither executes the template.

The template was dumped from generatePythonCode (columns textpos/neu/neg) and run against the pytexera in amber/src/main/python, in a virtualenv with the pinned transformers 5.5.0 and numpy 2.1.0. main's stops at line 4 with ImportError: cannot import name 'TFAutoModelForSequenceClassification' from 'transformers', before the class body is defined; this PR's loads cardiffnlp/twitter-roberta-base-sentiment-latest and classifies all three rows, each row's three columns summing to 1:

text pos neu neg
I love this new feature, it works beautifully! 0.9884 0.007 0.0046
The meeting is scheduled for 3pm in room 204. 0.0433 0.9438 0.0129
This is the worst release we have ever shipped. 0.0066 0.0423 0.951

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 4.8)

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @carloea2
    You can notify them by mentioning @carloea2 in a comment.

@codecov-commenter

codecov-commenter commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.37%. Comparing base (5a3da70) to head (edf0679).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6809      +/-   ##
============================================
- Coverage     83.20%   80.37%   -2.83%     
- Complexity     4117     4691     +574     
============================================
  Files          1166     1222      +56     
  Lines         46456    50684    +4228     
  Branches       5177     5760     +583     
============================================
+ Hits          38654    40739    +2085     
- Misses         6096     8096    +2000     
- Partials       1706     1849     +143     
Flag Coverage Δ *Carryforward flag
access-control-service 71.10% <ø> (+1.10%) ⬆️
agent-service 83.65% <ø> (ø) Carriedforward from ced81ee
amber 75.59% <ø> (-4.85%) ⬇️
computing-unit-managing-service 30.35% <ø> (-13.26%) ⬇️
config-service 64.02% <ø> (-1.96%) ⬇️
file-service 64.13% <ø> (-4.92%) ⬇️
frontend 83.55% <ø> (-0.29%) ⬇️ Carriedforward from ced81ee
notebook-migration-service 78.89% <ø> (ø)
pyamber 97.36% <ø> (-0.01%) ⬇️ Carriedforward from ced81ee
workflow-compiling-service 51.78% <ø> (+25.46%) ⬆️

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

… codegen

HuggingFaceSentimentAnalysisOpDesc.generatePythonCode imported
TFAutoModelForSequenceClassification but never used it (the model loads via the
PyTorch AutoModelForSequenceClassification). The TF-only symbol forces a
TensorFlow backend, so in a PyTorch-only transformers install the import raises
and crashes the generated script at module load. Remove the unused import.

Adds a HuggingFaceSentimentAnalysisOpDescSpec regression test asserting the
generated code no longer imports the TF-only symbol while still importing the
PyTorch class it uses.

Closes apache#6794

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kz930
kz930 force-pushed the fix/hf-sentiment-unused-tf-import-6794 branch from c76dc6b to b5303ed Compare July 22, 2026 23:13
@kz930

kz930 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@carloea2, @aglinxinyuan May any of you look at it please? Thank you.

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

✅ No material benchmark regressions detected

🟢 0 better · 🔴 0 worse · ⚪ 15 noise (<±5%) · 0 without baseline

Compared against main 5a3da70 benchmarked on this same runner, so the delta is largely free of cross-runner hardware noise. The "7d avg" column still reflects the gh-pages dashboard. Treat <±5% as noise unless repeated.

Dashboard · Run

config throughput MB/s latency max Δ latest / 7d
bs=10 sw=10 sl=64 450 0.274 20,708/30,940/30,940 us ⚪ within ±5% / 🔴 +99.1%
bs=100 sw=10 sl=64 972 0.593 100,306/125,128/125,128 us ⚪ within ±5% / 🔴 +14.7%
bs=1000 sw=10 sl=64 1,132 0.691 877,808/929,214/929,214 us ⚪ within ±5% / 🟢 -13.1%
Baseline details

Latest main 5a3da70 from same runner

config metric PR latest main 7d avg Δ latest Δ 7d
bs=10 sw=10 sl=64 throughput 450 tuples/sec 472 tuples/sec 767.32 tuples/sec -4.7% -41.4%
bs=10 sw=10 sl=64 MB/s 0.274 MB/s 0.288 MB/s 0.468 MB/s -4.9% -41.5%
bs=10 sw=10 sl=64 p50 20,708 us 20,258 us 12,772 us +2.2% +62.1%
bs=10 sw=10 sl=64 p95 30,940 us 32,221 us 15,538 us -4.0% +99.1%
bs=10 sw=10 sl=64 p99 30,940 us 32,221 us 18,948 us -4.0% +63.3%
bs=100 sw=10 sl=64 throughput 972 tuples/sec 985 tuples/sec 972.51 tuples/sec -1.3% -0.1%
bs=100 sw=10 sl=64 MB/s 0.593 MB/s 0.601 MB/s 0.594 MB/s -1.3% -0.1%
bs=100 sw=10 sl=64 p50 100,306 us 98,842 us 103,020 us +1.5% -2.6%
bs=100 sw=10 sl=64 p95 125,128 us 126,123 us 109,070 us -0.8% +14.7%
bs=100 sw=10 sl=64 p99 125,128 us 126,123 us 118,964 us -0.8% +5.2%
bs=1000 sw=10 sl=64 throughput 1,132 tuples/sec 1,131 tuples/sec 1,005 tuples/sec +0.1% +12.6%
bs=1000 sw=10 sl=64 MB/s 0.691 MB/s 0.69 MB/s 0.613 MB/s +0.1% +12.7%
bs=1000 sw=10 sl=64 p50 877,808 us 880,420 us 1,002,400 us -0.3% -12.4%
bs=1000 sw=10 sl=64 p95 929,214 us 937,263 us 1,039,228 us -0.9% -10.6%
bs=1000 sw=10 sl=64 p99 929,214 us 937,263 us 1,069,081 us -0.9% -13.1%
Raw CSV
config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
0,10,10,64,20,444.87,200,128000,450,0.274,20708.40,30940.25,30940.25
1,100,10,64,20,2057.43,2000,1280000,972,0.593,100305.90,125127.51,125127.51
2,1000,10,64,20,17673.46,20000,12800000,1132,0.691,877808.41,929214.26,929214.26

Copilot AI 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.

Pull request overview

This PR fixes HuggingFace Sentiment Analysis Python code generation by removing an unused TensorFlow-only transformers import that can crash the generated script in PyTorch-only environments, aligning behavior with the operator’s actual PyTorch usage (Closes #6794).

Changes:

  • Remove the unused TFAutoModelForSequenceClassification import from the generated Python code.
  • Add a regression test ensuring the TF-only symbol is not emitted while the PyTorch AutoModelForSequenceClassification import remains present.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSentimentAnalysisOpDesc.scala Drops the unused TensorFlow-only import from generatePythonCode() output.
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSentimentAnalysisOpDescSpec.scala Adds regression coverage verifying the generated code no longer contains the TF-only import.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@aglinxinyuan

Copy link
Copy Markdown
Contributor

Please fix the ci

The assertion only guards a line in generatePythonCode() that is slated
for removal, so it adds little lasting value. Keep the import fix itself.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kz930

kz930 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

CI green now — the title check was a transient failure, re-triggered by the new push. Also removed the test per @Yicong-Huang (4defe25). Thanks!

@Yicong-Huang

Copy link
Copy Markdown
Contributor

CI green now — the title check was a transient failure, re-triggered by the new push. Also removed the test per @Yicong-Huang (4defe25). Thanks!

Please don't forget to update PR description ;)

@kz930

kz930 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Done, updated the description.

@Yicong-Huang

Yicong-Huang commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Do we have a way to test and verify the generated python code can run as expected?

cc @carloea2 to see if you have context on this?

@aglinxinyuan

aglinxinyuan commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Do we have a way to test and verify the generated python code can run as expected?

cc @carloea2 to see if you have context on this?

It's a separate topic, shouldn't block this PR.

I think currently all Python operators are untested by Python interpreter.

@Yicong-Huang

Copy link
Copy Markdown
Contributor

If there are no programmatical tests, I will ask @kz930 to manually test and report the result in PR description. Thanks.

@carloea2

Copy link
Copy Markdown
Contributor

@Yicong-Huang

I made a programmatic test to check all python operators generated code can py_compile. However it does not run them because of 2 reasons:

Increased run time.
How to feed meaningful smoke data.

Do you think is good idea to actually run them to fully test them?

@carloea2

Copy link
Copy Markdown
Contributor

Also the test is supposed to check the operator correctly uses and don't forget to use Python template builder.

@Yicong-Huang

Copy link
Copy Markdown
Contributor

@Yicong-Huang

I made a programmatic test to check all python operators generated code can py_compile. However it does not run them because of 2 reasons:

Increased run time. How to feed meaningful smoke data.

Do you think is good idea to actually run them to fully test them?

I think it will be great to have these added to CI! we can just ask each operator author/maintainer to provide a script to generate smoke data. Your test should provide an API to get data and get operator.

For this PR, if we have manual test, I am fine with it. We can push the programmatic test to future work. @carloea2 do you have an issue for it?

@carloea2

Copy link
Copy Markdown
Contributor

I do not have an issue, that test was merged in the next PR: #4189

Do you want an issue for also running them?

@kz930

kz930 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Manually verified, numbers in the description: with the pinned transformers 5.5.0 the current template dies at ImportError: cannot import name 'TFAutoModelForSequenceClassification', while with this PR it classifies three rows correctly.

For a programmatic version — #7207 routes tests that actually run generated code to amber-integration, where torch and transformers are installed; the amber job installs no Python packages, which is why such a test has nowhere to live today.

@Yicong-Huang Yicong-Huang added the release/v1.2 back porting to release/v1.2 label Aug 3, 2026
@github-actions
github-actions Bot requested a review from xuang7 August 3, 2026 20:18
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Backport auto-label report

This fix: PR was checked against each actively-supported release branch. release/* labels drive the post-merge backport, so add or remove one to change where this fix lands.

Release branch Analysis
release/v1.2 Change detected on this branch — label added; this fix is queued to backport here. Requested review from @xuang7.

Auto-label run.

@xuang7 xuang7 added release/v1.2 back porting to release/v1.2 and removed release/v1.2 back porting to release/v1.2 labels Aug 4, 2026
@xuang7
xuang7 added this pull request to the merge queue Aug 5, 2026
Merged via the queue into apache:main with commit 2ae9a97 Aug 5, 2026
111 of 125 checks passed
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Backport PR opened: draft #7315 (#7315) to release/v1.2, assigned to @kz930 — needs manual work because the backported tree failed its pre-merge build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common fix release/v1.2 back porting to release/v1.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HuggingFaceSentimentAnalysis: generated code has an unused TensorFlow import

7 participants