Add models to benchmarks#40820
Conversation
|
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. |
|
cc @ArthurZucker maybe? Not sure who's working on the benchmarking |
ArthurZucker
left a comment
There was a problem hiding this comment.
Comments apply to all the files added here
| def __init__(self, logger: logging.Logger): | ||
| super().__init__(logger) | ||
| self._default_prompt = "Why dogs are so cute?" |
There was a problem hiding this comment.
I think in general we'd want to run the models on the exact same prompts all the time no? it does not really matter anyways but I would decorelate this from the model
| {"variant": "eager", "compile_mode": None, "use_cache": True, "description": "Eager execution with cache"}, | ||
| { | ||
| "variant": "compiled", | ||
| "compile_mode": "max-autotune", | ||
| "use_cache": True, | ||
| "description": "Compiled with max autotune", | ||
| }, | ||
| { | ||
| "variant": "kernelized", | ||
| "compile_mode": "max-autotune", | ||
| "use_cache": True, | ||
| "description": "Kernelized execution", | ||
| }, | ||
| ] |
There was a problem hiding this comment.
these are common IMO, not specific to bert, hsould not be seen here
| def _is_kernelization_available(self) -> bool: | ||
| """Check if kernelization is available for BERT.""" | ||
| try: | ||
| from kernels import Mode, kernelize # noqa: F401 | ||
|
|
||
| return True | ||
| except ImportError: | ||
| self.logger.debug("Kernelization not available: kernels module not found") | ||
| return False |
There was a problem hiding this comment.
not really true, we should check if the model has a use_kernel_from_hub and have the kernel scenario activate only if model has them
| def get_default_generation_config(self) -> dict[str, Any]: | ||
| """Get BERT-specific generation configuration.""" | ||
| return { | ||
| "do_sample": False, | ||
| "top_p": 1.0, | ||
| "temperature": 1.0, | ||
| "repetition_penalty": 1.0, | ||
| "max_new_tokens": None, | ||
| } |
There was a problem hiding this comment.
that's not default to bert
| def get_model_init_kwargs(self, config) -> dict[str, Any]: | ||
| """Get BERT-specific model initialization kwargs.""" | ||
| return { | ||
| "torch_dtype": getattr(torch, config.torch_dtype), | ||
| "attn_implementation": config.attn_implementation, | ||
| "use_cache": True, | ||
| } | ||
|
|
||
| def get_default_torch_dtype(self) -> str: | ||
| """Get default torch dtype for BERT.""" | ||
| return "float16" | ||
|
|
||
| def get_default_device(self) -> str: | ||
| """Get default device for BERT.""" | ||
| return "cuda" |
There was a problem hiding this comment.
nothing specific here, should be in the base model AFAI can see
| def run_bert(logger, output_dir, **kwargs): | ||
| """ | ||
| Run BERT benchmark with the given configuration. | ||
|
|
||
| Args: | ||
| logger: Logger instance | ||
| output_dir: Output directory for results | ||
| **kwargs: Additional configuration options | ||
|
|
||
| Returns: | ||
| Path to output file if successful | ||
| """ | ||
| from benchmark_framework import BenchmarkRunner | ||
|
|
||
| # Extract parameters with defaults | ||
| model_id = kwargs.get("model_id", "bert-base-uncased") | ||
| warmup_iterations = kwargs.get("warmup_iterations", 3) | ||
| measurement_iterations = kwargs.get("measurement_iterations", 5) | ||
| num_tokens_to_generate = kwargs.get("num_tokens_to_generate", 100) | ||
| include_sdpa_variants = kwargs.get("include_sdpa_variants", True) | ||
| device = kwargs.get("device", "cuda") | ||
| torch_dtype = kwargs.get("torch_dtype", "float16") | ||
| batch_size = kwargs.get("batch_size", 1) | ||
| commit_id = kwargs.get("commit_id") |
There was a problem hiding this comment.
this is also classic / should be shared by all model
| # Create benchmark instance | ||
| benchmark = BERTBenchmark(logger) | ||
|
|
||
| # Create scenarios | ||
| scenarios = benchmark.create_scenarios( | ||
| model_id=model_id, | ||
| warmup_iterations=warmup_iterations, | ||
| measurement_iterations=measurement_iterations, | ||
| num_tokens_to_generate=num_tokens_to_generate, | ||
| include_sdpa_variants=include_sdpa_variants, | ||
| device=device, | ||
| torch_dtype=torch_dtype, | ||
| batch_size=batch_size, | ||
| ) | ||
|
|
||
| logger.info(f"Created {len(scenarios)} benchmark scenarios") | ||
|
|
||
| # Create runner and execute benchmarks | ||
| runner = BenchmarkRunner(logger, output_dir) | ||
| results = runner.run_benchmark(benchmark, scenarios, commit_id=commit_id) | ||
|
|
||
| if not results: | ||
| logger.warning("No successful benchmark results") | ||
| return None | ||
|
|
||
| # Save results | ||
| model_name = model_id.split("/")[-1] # Extract model name from ID | ||
| output_file = runner.save_results(model_name, results) | ||
|
|
||
| logger.info(f"BERT benchmark completed successfully. Results saved to: {output_file}") | ||
| return output_file |
What does this PR do?
This PR adds bert, gemma3, gpt, mistral3 and qwen2 to the new benchmarking pipeline.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.