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

use ahash in ngram #48

Merged
merged 2 commits into from
May 16, 2024
Merged

use ahash in ngram #48

merged 2 commits into from
May 16, 2024

Conversation

shenxiangzhuang
Copy link
Owner

@shenxiangzhuang shenxiangzhuang commented May 16, 2024

Summary by CodeRabbit

  • Performance Improvements
    • Enhanced efficiency in n-gram token counting by switching to a more performant hash map implementation.

@shenxiangzhuang shenxiangzhuang self-assigned this May 16, 2024
Copy link

github-actions bot commented May 16, 2024

🐰Bencher

ReportThu, May 16, 2024 at 02:00:22 UTC
Projectbleuscore
Branchchange/use_ahash_in_ngram
Testbedubuntu-latest

⚠️ WARNING: The following Measure does not have a Threshold. Without a Threshold, no Alerts will ever be generated!

  • Latency (latency)

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds CLI flag.

Click to view all benchmark results
BenchmarkLatencyLatency Results
nanoseconds (ns)
bleu::benchmark::bench_batch_bleu➖ (view plot)12,010,099.10
bleu::benchmark::bench_bleu➖ (view plot)248,226.17
ngram::benchmark::bench_ngram➖ (view plot)50,354.25
tokenizer::benchmark::bench_tokenizer➖ (view plot)15,824.03

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

Copy link
Contributor

coderabbitai bot commented May 16, 2024

Walkthrough

The recent update enhances the n-gram module by transitioning to ahash::AHashMap from std::collections::HashMap in src/ngram.rs for improved performance. This change impacts the return type of get_token_ngram_counter function. The CHANGELOG.md now reflects this update, while no other public entities have been modified.

Changes

File Change Summary
CHANGELOG.md Updated to indicate the use of AHash in the ngram module.
src/ngram.rs Switched from HashMap to AHashMap for token n-gram counts; updated function return type.

🐇
In the realm of code where n-grams play,
AHashMap now leads the way.
Speed and grace in every byte,
Tokens counted, day and night.
A rabbit's hop, a coder's cheer,
For optimized paths, we hold dear.
🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Out of diff range and nitpick comments (1)
src/ngram.rs (1)

2-2: Consider adding a comment explaining the choice of AHashMap for future maintainers.

use ahash::AHashMap; // Chosen for performance benefits over std::collections::HashMap
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 97da600 and ef3cb8c.
Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • src/ngram.rs (1 hunks)
Additional comments not posted (1)
src/ngram.rs (1)

Line range hint 6-13: The function get_token_ngram_counter looks good with the change to AHashMap. Ensure that all usages of this function are updated to handle the new return type.

Verification successful

The function get_token_ngram_counter is used in both src/ngram.rs and src/bleu.rs. The return type AHashMap<&[String], usize> is used in assertions in src/ngram.rs and in hash map operations in src/bleu.rs.

Verification of Usage in src/ngram.rs

  • The test cases in src/ngram.rs use the return type in assertions, which indicates that the return type is being correctly handled in the context of the tests.

Verification of Usage in src/bleu.rs

  • The code in src/bleu.rs uses the return type in hash map operations, such as merging hash maps. The operations appear to be correctly handling the AHashMap<&[String], usize> type.

Based on the extracted lines, it appears that all usages of the function get_token_ngram_counter correctly handle the new return type AHashMap<&[String], usize>.

Conclusion

The verification confirms that all instances of get_token_ngram_counter handle the new return type correctly.

  • : All usages of the function get_token_ngram_counter handle the new return type AHashMap<&[String], usize> correctly.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all function calls to `get_token_ngram_counter` handle the new return type.

# Test: Search for the function usage. Expect: Only occurrences of the new return type.
rg --type rust 'get_token_ngram_counter'

Length of output: 656



Script:

#!/bin/bash
# Extract and review the relevant lines of code where `get_token_ngram_counter` is used.

# Extract lines around the usage in src/ngram.rs
echo "Occurrences in src/ngram.rs:"
rg --context 5 'get_token_ngram_counter' src/ngram.rs

# Extract lines around the usage in src/bleu.rs
echo "Occurrences in src/bleu.rs:"
rg --context 5 'get_token_ngram_counter' src/bleu.rs

Length of output: 2514

Comment on lines +10 to +11

### Changed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the extra blank line.

## [Unreleased]

-### Changed
+### Changed

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
### Changed
## [Unreleased]
### Changed

Comment on lines +11 to +13
### Changed
- Use AHash in ngram module

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surround the list with blank lines.

-### Changed
+### Changed

- Use AHash in ngram module
+ - Use AHash in ngram module

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
### Changed
- Use AHash in ngram module
### Changed
- Use AHash in ngram module

Copy link

codecov bot commented May 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.05%. Comparing base (97da600) to head (5e77047).

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #48   +/-   ##
=======================================
  Coverage   85.05%   85.05%           
=======================================
  Files           4        4           
  Lines         368      368           
=======================================
  Hits          313      313           
  Misses         55       55           

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between ef3cb8c and 5e77047.
Files selected for processing (1)
  • src/ngram.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/ngram.rs

@shenxiangzhuang shenxiangzhuang merged commit 8785907 into master May 16, 2024
14 checks passed
@shenxiangzhuang shenxiangzhuang deleted the change/use_ahash_in_ngram branch May 16, 2024 02:02
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