promptflow icon indicating copy to clipboard operation
promptflow copied to clipboard

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

Open zzn2 opened this issue 1 year ago • 7 comments

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 only adds the fields that are integers.

All Promptflow Contribution checklist:

  • [x] The pull request does not introduce [breaking changes].
  • [ ] CHANGELOG is updated for new features, bug fixes or other significant changes.
  • [x] I have read the contribution guidelines.
  • [x] 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 avatar Sep 29 '24 15:09 zzn2

promptflow-tracing test result

 12 files  ±0   12 suites  ±0   16s :stopwatch: -1s  62 tests ±0   62 :white_check_mark: ±0  0 :zzz: ±0  0 :x: ±0  744 runs  ±0  744 :white_check_mark: ±0  0 :zzz: ±0  0 :x: ±0 

Results for commit c8ef3b27. ± Comparison against base commit 11ac34bd.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Sep 29 '24 15:09 github-actions[bot]

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

  4 files    4 suites   4m 18s :stopwatch: 244 tests 204 :white_check_mark:  40 :zzz: 0 :x: 976 runs  816 :white_check_mark: 160 :zzz: 0 :x:

Results for commit c8ef3b27.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Sep 29 '24 15:09 github-actions[bot]

promptflow-core test result

0 tests  ±0   0 :white_check_mark: ±0   0s :stopwatch: ±0s 0 suites ±0   0 :zzz: ±0  0 files   ±0   0 :x: ±0 

Results for commit c8ef3b27. ± Comparison against base commit 11ac34bd.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Sep 29 '24 15:09 github-actions[bot]

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

6 tests   6 :white_check_mark:  1m 23s :stopwatch: 1 suites  0 :zzz: 1 files    0 :x:

Results for commit c8ef3b27.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Sep 29 '24 15:09 github-actions[bot]

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

798 tests   798 :white_check_mark:  3m 43s :stopwatch:   1 suites    0 :zzz:   1 files      0 :x:

Results for commit c8ef3b27.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Sep 29 '24 15:09 github-actions[bot]

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

246 tests   239 :white_check_mark:  5m 15s :stopwatch:   1 suites    6 :zzz:   1 files      1 :x:

For more details on these failures, see this check.

Results for commit c8ef3b27.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Sep 29 '24 15:09 github-actions[bot]

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

    4 files      4 suites   1h 5m 37s :stopwatch:   790 tests   767 :white_check_mark: 23 :zzz: 0 :x: 3 160 runs  3 068 :white_check_mark: 92 :zzz: 0 :x:

Results for commit c8ef3b27.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Sep 29 '24 16:09 github-actions[bot]