Skip to content

feat(kaggle-cli): Add sdk for benchmark notebook#90

Open
dolaameng wants to merge 5 commits intocifrom
dolaameng/kaggle_client_2
Open

feat(kaggle-cli): Add sdk for benchmark notebook#90
dolaameng wants to merge 5 commits intocifrom
dolaameng/kaggle_client_2

Conversation

@dolaameng
Copy link
Copy Markdown
Collaborator

@dolaameng dolaameng commented Mar 24, 2026

Kaggle Benchmark Client

This PR introduces the BenchmarkNotebookClient SDK to manage Kaggle benchmark tasks. These tasks execute as Kaggle notebooks tagged with the personal-benchmark keyword.

APIs

  • publish_and_run: Converts local Python benchmark scripts into .ipynb format, generates the kernel-metadata.json file (allowing users to persistently save and edit kernel configuration overrides), and pushes the payload to Kaggle. Implements concurrent run guards to block overlapping executions of the same benchmark (bypassable via force=True).
  • fork: Pulls pre-existing benchmark notebooks from Kaggle into local workspaces for editing.
  • get_results: Polls the Kaggle backend for execution status and retrieves one or more .run.json artifacts upon completion. Supports thread-based polling cancellation via threading.Event.

Testing

The code is validated by two test suites:

  • test_notebook_api.py: Uses API mocks to verify polling logic, artifact extraction, and cancellation offline.
  • test_kaggle_client.py: Runs against the live Kaggle backend (golden_tests) to test the full execution lifecycle.

@dolaameng dolaameng changed the title feat(kaggle-cli): Add sdk for task run. feat(kaggle-cli): Add sdk for benchmark notebook Mar 25, 2026
# ---------------------------------------------------------------------------


def normalize_status(status: object) -> str:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might want a narrower type here. object seems not what you intended; see Any vs object.

Suggested change
def normalize_status(status: object) -> str:
def normalize_status(status: Any) -> str:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes! Done.

Comment on lines +30 to +37
from kaggle_benchmarks.kaggle_client.utils import (
KAGGLE_METADATA_MAP,
build_local_metadata,
convert_ipynb_to_py,
convert_py_to_ipynb,
normalize_status,
parse_remote_metadata,
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might be clearer to import as a module. It usually makes the code easier to follow; style guide

Suggested change
from kaggle_benchmarks.kaggle_client.utils import (
KAGGLE_METADATA_MAP,
build_local_metadata,
convert_ipynb_to_py,
convert_py_to_ipynb,
normalize_status,
parse_remote_metadata,
)
from kaggle_benchmarks.kaggle_client import utils as kaggle_utils

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we move most of this to the kagglesdk? It seems out of scope for the benchmark package and may overlap with https://github.com/Kaggle/kaggle-sdk-python/tree/main/kagglesdk/benchmarks

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes that's another option.

  1. Ideally I think we want most heavy works implemented on kagglesdk and we have thin wrappers here for users to directly use without jumping around.
  2. Also it feels more nature to have all kinds of extensions like kaggle-client, vscode-exension together here for community contributions.

We could move part of the code to kagglesdk later, if people find this useful?

Comment on lines +262 to +275
meta = MagicMock()
meta.ref = "alice/my-benchmark"
meta.title = "My Benchmark"
meta.language = "python"
meta.kernel_type = "notebook"
meta.is_private = False
meta.enable_gpu = True
meta.enable_internet = True
meta.enable_tpu = False
meta.dataset_data_sources = ["alice/dataset"]
meta.competition_data_sources = ["comp1"]
meta.kernel_data_sources = ["alice/kernel"]
meta.model_data_sources = ["alice/model"]
meta.category_ids = ["personal-benchmark", "nlp"]
Copy link
Copy Markdown
Contributor

@s-alexey s-alexey Mar 25, 2026

Choose a reason for hiding this comment

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

Here and in other places I would advise against mocking when you can use dependency injections [go/python-tips/013]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes here meta is a mocked data object, and parse_remote_metadata takes it as a parameter so it's already DI?

Copy link
Copy Markdown

@rosbo rosbo left a comment

Choose a reason for hiding this comment

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

Link to my comment thread about adding this to our existing CLI rather than having a separate CLI tool. Let's discuss on that thread: https://docs.google.com/document/d/1xvOIzSAyYVNtff4S7aqELPNEpbAwmiem16jM68pzqJI/edit?disco=AAAB2hylHpA

gastondana627 added a commit to gastondana627/kaggle-benchmarks that referenced this pull request Mar 28, 2026
Adds a kaggle-bench CLI with two subcommands:
- run: publish and run a local benchmark script on Kaggle
- fork: pull an existing Kaggle benchmark notebook for local editing

Extends the BenchmarkNotebookClient SDK from PR Kaggle#90 with a
command-line interface so users can trigger benchmark runs
directly from the terminal without writing Python boilerplate.

Tests: 5 new unit tests covering help output, argument
parsing, and correct delegation to BenchmarkNotebookClient.
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.

3 participants