Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/memory-bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Memory benchmark

on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
pull-requests: write

env:
CARGO_TERM_COLOR: always

jobs:
bench:
name: memory before vs after
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Check out base
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base

- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable

- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
with:
key: memory-bench

- name: Cache models
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: models
key: fastembed-models-nomic-v1

# Both builds share one target dir so dependencies compile once.
- name: Build base and head
run: |
mkdir -p bin
cargo build --release --manifest-path base/Cargo.toml --target-dir target --bin embedding
cp target/release/embedding bin/base
cargo build --release --bins --example bench_memory
cp target/release/embedding bin/head

- name: Download model
run: target/release/warmup
env:
EMBEDDING_MODELS: nomic
EMBEDDING_CACHE_DIR: ${{ github.workspace }}/models

- name: Run benchmark
run: |
target/release/examples/bench_memory \
--base bin/base --head bin/head \
--cache-dir "$GITHUB_WORKSPACE/models" \
--out bench.md
{
echo "<!-- memory-bench -->"
echo "### Memory benchmark"
echo
echo "Base \`${BASE_SHA:0:7}\` vs head \`${HEAD_SHA:0:7}\` on \`ubuntu-latest\`."
echo
cat bench.md
} > comment.md
cat comment.md >> "$GITHUB_STEP_SUMMARY"
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}

# Fork PRs get a read-only token, so they only get the job summary.
- name: Comment on PR
if: github.event.pull_request.head.repo.full_name == github.repository
run: |
id=$(gh api "repos/$REPO/issues/$PR/comments" --paginate \
-q '.[] | select(.body | startswith("<!-- memory-bench -->")) | .id' | head -n1)
if [ -n "$id" ]; then
gh api -X PATCH "repos/$REPO/issues/comments/$id" -F body=@comment.md > /dev/null
else
gh pr comment "$PR" --repo "$REPO" --body-file comment.md
fi
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
PR: ${{ github.event.pull_request.number }}
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ axum = "0.8.7"
fastembed = "5.15.0"
futures = "0.3.32"
hf-hub = "0.5.0"
# Pinned to the ort fastembed uses so the CPU provider type matches.
ort = { version = "=2.0.0-rc.13", default-features = false, features = ["std"] }
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.145"
sysinfo = "0.39.2"
Expand All @@ -18,3 +20,7 @@ tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }

[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = { version = "0.6", features = ["override_allocator_on_supported_platforms"] }

[dev-dependencies]
# HTTP client for examples/bench_memory.rs; already in the tree via hf-hub.
ureq = { version = "3.3.0", default-features = false }
Loading
Loading