Skip to content

fix: add guards against ZeroDivisionError across cloud-edge LLM metrics and backends#547

Open
Fahmid-Arman wants to merge 1 commit into
kubeedge:mainfrom
Fahmid-Arman:fix-cloud-edge-zerodiv
Open

fix: add guards against ZeroDivisionError across cloud-edge LLM metrics and backends#547
Fahmid-Arman wants to merge 1 commit into
kubeedge:mainfrom
Fahmid-Arman:fix-cloud-edge-zerodiv

Conversation

@Fahmid-Arman

Copy link
Copy Markdown

What type of PR is this?
/kind bug

What this PR does / why we need it:
The cloud-edge-collaborative-inference-for-llm benchmark previously crashed with a ZeroDivisionError when executed against an empty dataset or when a model generated $\le1$ token (e.g., immediate EOS).

This PR implements comprehensive, zero-safe division guards across the 5 metric modules and 4 backend wrappers to ensure the framework returns 0.0 gracefully under these edge cases, preserving the execution of the broader benchmark suite.

Files patched:
Metrics:

  • testenv/accuracy.py
  • testenv/throughput.py
  • testenv/internal_token_latency.py
  • testenv/time_to_first_token.py
  • testenv/edge_ratio.py

Backends:

  • models/huggingface_llm.py
  • models/vllm_llm.py
  • models/eagle_llm.py
  • models/api_llm.py (Identified and patched proactively)

Which issue(s) this PR fixes:
Fixes #337

@kubeedge-bot kubeedge-bot added the kind/bug Categorizes issue or PR as related to a bug. label Jun 14, 2026
@kubeedge-bot kubeedge-bot requested review from Poorunga and hsj576 June 14, 2026 11:12
@kubeedge-bot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Fahmid-Arman
To complete the pull request process, please assign moorezheng after the PR has been reviewed.
You can assign the PR to them by writing /assign @moorezheng in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeedge-bot kubeedge-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 14, 2026

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

Copy link
Copy Markdown

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 improves the robustness of LLM inference and evaluation scripts by adding checks to prevent division-by-zero errors when calculating token latency, throughput, and other metrics. The feedback recommends adhering to PEP 8 guidelines by using implicit boolean evaluation for empty sequences instead of checking their length with len() > 0.

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.

…cs and backends

Signed-off-by: Fahmid Arman <fahmid.brac@gmail.com>
@Fahmid-Arman Fahmid-Arman force-pushed the fix-cloud-edge-zerodiv branch from 52e6e60 to 83b52ff Compare June 14, 2026 11:16
@Fahmid-Arman

Copy link
Copy Markdown
Author

Feedback addressed:

  • Refactored empty sequence checks to use PEP 8 compliant implicit boolean evaluation (if internal_token_latency:) instead of len() > 0.

/assign @MooreZheng

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

Labels

kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unguarded divisions crash with empty datasets in cloud-edge LLM example

3 participants