Skip to content

Benchmark command fixes#220

Closed
drbh wants to merge 3 commits intomainfrom
benchmark-command-fixes
Closed

Benchmark command fixes#220
drbh wants to merge 3 commits intomainfrom
benchmark-command-fixes

Conversation

@drbh
Copy link
Collaborator

@drbh drbh commented Jan 22, 2026

This PR

  • adds a small fix to the get_kernel_sha_from_build_name as the name parsing was not working with arbitrary kernels.
  • hotfixes the _synchronize that had a typo from the previous changes
  • adds layer norm benchmarking function for layer_norm
  • adds a --benchmarks and --benchmarks-only flag to the upload subcommand to upload the benchmark directory

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@MekkCyber MekkCyber left a comment

Choose a reason for hiding this comment

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

very nice!

Comment on lines 231 to 233
delete_patterns=["benchmark*.py"],
commit_message="Benchmarks uploaded using `kernels`.",
allow_patterns=["benchmark*.py"],
Copy link
Collaborator

Choose a reason for hiding this comment

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

small nit: delete_patterns are the same as allow_patterns, is this expected

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah yea this is strange looking syntax but I believe its correct, since I think this is how to specify which files to overwrite/remove if they don't exist in the latest local copy of the dir.

Copy link
Collaborator

Choose a reason for hiding this comment

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

makes sense! thanks for clarifying

Comment on lines 217 to 223
repo_id = create_repo(
repo_id=args.repo_id, private=args.private, exist_ok=True
).repo_id

if args.branch is not None:
create_branch(repo_id=repo_id, branch=args.branch, exist_ok=True)

Copy link
Member

Choose a reason for hiding this comment

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

With the versions PR merged, this needs a sync against the version handling.

@drbh drbh force-pushed the benchmark-command-fixes branch from a7d7242 to e3ee2af Compare January 23, 2026 14:37
@drbh drbh force-pushed the benchmark-command-fixes branch from e3ee2af to 41dff23 Compare January 23, 2026 14:48
@drbh
Copy link
Collaborator Author

drbh commented Jan 23, 2026

updates

the upload command now uses the version in two cases

  1. parsed from the build.toml if --benchmarks-only is applied, which aims to allow users to update benches in cases where no new builds are added ie; kernels upload --repo-id kernels-community/activation --benchmarks-only .
  2. as the default upload flow using the version parsed from the metadata.json file (same as the kernel upload)

the benchmark command now requires a branch or version to be specified. the following are valid commands

  1. kernels benchmark kernels-community/flash-attn2 --version 1
  2. kernels benchmark kernels-community/flash-attn2 --branch v1
  3. kernels benchmark kernels-community/flash-attn2@v1

note that

  1. kernels benchmark kernels-community/flash-attn2@1 is not valid and will warn that a v is needed

Comment on lines +26 to +48
if benchmarks_only:
metadata = Metadata.load_from_build_toml(kernel_dir / "build.toml")
if metadata.version is None:
raise ValueError(
f"Cannot upload benchmarks only without a version specified in build.toml at: {(kernel_dir / 'build.toml').absolute()}"
)

branch = f"v{metadata.version}"

upload_folder(
repo_id=repo_id,
folder_path=kernel_dir / "benchmarks",
revision=branch,
path_in_repo="benchmarks",
delete_patterns=["benchmark*.py"],
commit_message="Benchmarks uploaded using `kernels`.",
allow_patterns=["benchmark*.py"],
)

print(
f"✅ Benchmarks upload successful. Find the kernel in: https://hf.co/{repo_id}"
)
return # Exit if only benchmarks are to be uploaded
Copy link
Member

Choose a reason for hiding this comment

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

I think we should completely remove the benchmark_only case:

  • It would only be useful in the case one also has built kernels, but only wants to upload the benchmark, which seems very rare. (And if no kernels were built, there is no additional cost, since existing variants will not be uploaded again).
  • It relies on the existence of build.toml, but this file may not be present (e.g. if someone has their own build infra).
  • I makes the upload logic quite a bit more complex.

In the very rare case where the first point happens, someone could use the huggingface CLI to upload.

@danieldk danieldk mentioned this pull request Jan 24, 2026
@drbh
Copy link
Collaborator Author

drbh commented Jan 26, 2026

closing in favor of #229

@drbh drbh closed this Jan 26, 2026
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.

4 participants