Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add models to benchmarks#40820

Open
ahadnagy wants to merge 4 commits into
huggingface:mainfrom
ahadnagy:add-models-to-benchmarks
Open

Add models to benchmarks#40820
ahadnagy wants to merge 4 commits into
huggingface:mainfrom
ahadnagy:add-models-to-benchmarks

Conversation

@ahadnagy

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR adds bert, gemma3, gpt, mistral3 and qwen2 to the new benchmarking pipeline.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

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.

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

@Rocketknight1

Copy link
Copy Markdown
Member

cc @ArthurZucker maybe? Not sure who's working on the benchmarking

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comments apply to all the files added here

Comment on lines +30 to +32
def __init__(self, logger: logging.Logger):
super().__init__(logger)
self._default_prompt = "Why dogs are so cute?"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Comment thread benchmark_v2/benches/bert.py Outdated
Comment on lines +42 to +55
{"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",
},
]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

these are common IMO, not specific to bert, hsould not be seen here

Comment thread benchmark_v2/benches/bert.py Outdated
Comment on lines +57 to +65
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Comment thread benchmark_v2/benches/bert.py Outdated
Comment on lines +67 to +75
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,
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

that's not default to bert

Comment on lines +77 to +91
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"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nothing specific here, should be in the base model AFAI can see

Comment thread benchmark_v2/benches/bert.py Outdated
Comment on lines +94 to +117
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")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is also classic / should be shared by all model

Comment on lines +125 to +155
# 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is classic

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