Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in token usage merging logic for promptflow-tracing SDK #3793

Merged
merged 4 commits into from
Oct 8, 2024

Conversation

zzn2
Copy link
Contributor

@zzn2 zzn2 commented Sep 29, 2024

Description

The token calculation logic in promptflow-tracing merges two dictionaries related to token usage.
i.e. Given these two dictionaries:

{ "completion_tokens": 146, "prompt_tokens": 166, "total_tokens": 312 }
{ "completion_tokens": 10, "prompt_tokens": 10, "total_tokens": 20 }

The merged result will be:

{ "completion_tokens": 156, "prompt_tokens": 176, "total_tokens": 332 }

However, for some customized models, there might be more additional fields populated in the dictionaries, like:

{ "completion_tokens": 146, "prompt_tokens": 166, "total_tokens": 312, "completion_tokens_details": null }

Which causes the merging logic crash:

image

This PR is to fix the issue. It converts nulls to 0s to avoid Python from raising errors.

All Promptflow Contribution checklist:

  • The pull request does not introduce [breaking changes].
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.
  • I confirm that all new dependencies are compatible with the MIT license.
  • Create an issue and link to the pull request to get dedicated review from promptflow team. Learn more: suggested workflow.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@zzn2 zzn2 requested a review from a team as a code owner September 29, 2024 15:41
@zzn2 zzn2 changed the title only add when both of the side are int Fix bug in promptflow tracing token calculation logic Sep 29, 2024
@zzn2 zzn2 changed the title Fix bug in promptflow tracing token calculation logic Fix bug in token usage merging logic for tracing SDK Sep 29, 2024
@zzn2 zzn2 changed the title Fix bug in token usage merging logic for tracing SDK Fix bug in token usage merging logic for promptflow-tracing SDK Sep 29, 2024
Copy link

github-actions bot commented Sep 29, 2024

promptflow-tracing test result

 12 files  ±0   12 suites  ±0   16s ⏱️ -1s
 62 tests ±0   62 ✅ ±0  0 💤 ±0  0 ❌ ±0 
744 runs  ±0  744 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit c8ef3b2. ± Comparison against base commit 11ac34b.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Sep 29, 2024

promptflow SDK CLI Azure E2E Test Result u/zhizhu/20240929-fix-tracing-bug

  4 files    4 suites   4m 18s ⏱️
244 tests 204 ✅  40 💤 0 ❌
976 runs  816 ✅ 160 💤 0 ❌

Results for commit c8ef3b2.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Sep 29, 2024

promptflow-core test result

0 tests  ±0   0 ✅ ±0   0s ⏱️ ±0s
0 suites ±0   0 💤 ±0 
0 files   ±0   0 ❌ ±0 

Results for commit c8ef3b2. ± Comparison against base commit 11ac34b.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Sep 29, 2024

SDK CLI Global Config Test Result u/zhizhu/20240929-fix-tracing-bug

6 tests   6 ✅  1m 23s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit c8ef3b2.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Sep 29, 2024

Executor Unit Test Result u/zhizhu/20240929-fix-tracing-bug

798 tests   798 ✅  3m 43s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit c8ef3b2.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Sep 29, 2024

Executor E2E Test Result u/zhizhu/20240929-fix-tracing-bug

246 tests   239 ✅  5m 15s ⏱️
  1 suites    6 💤
  1 files      1 ❌

For more details on these failures, see this check.

Results for commit c8ef3b2.

♻️ This comment has been updated with latest results.

luigiw
luigiw previously approved these changes Oct 7, 2024
@luigiw luigiw dismissed stale reviews from ninghu and themself via c8ef3b2 October 7, 2024 23:06
@ninghu ninghu merged commit f08e576 into main Oct 8, 2024
60 of 77 checks passed
@ninghu ninghu deleted the u/zhizhu/20240929-fix-tracing-bug branch October 8, 2024 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants