kernelfoundry.algorithm.utils.kernelbench_dataset

Functions

assign_problem_hash(problem_path)

Assign a unique hash to a problem in the dataset

create_custom_task_files(tmpdir, config, ...)

Fill the KernelBench template with the given reference and config and other info, copy to tmpdir

get_code_hash(problem_src)

Assign a unique hash to some piece of code Important to strip out the comments and whitespace as they are not functionally part of the code

get_id_to_name_mapping(level)

get_kernelbench_subset(data_config)

Construct task_set from configuration

get_kernelbench_task_id(task_name)

Get ID of KernelBench task from database

get_problem_list_by_level(level)

get_robust_kbench_task_list(config)

Get dictionary of available tasks for robust-kbench.

init_pytorch_functionals()

Load functionals csv if not yet in memory

kernelbench_reference_to_custom_task(...)

Convert KernelBench task for Task object

load_kernelbench_task(config, task_name[, ...])

Load KernelBench task either from database or csv file, return as string or as customTask :param config: config with job parameters :param task_name: name of the operation :type task_name: str :param from_db: if True, load from db (otherwise load from csv) :type from_db: bool :param as_custom_task: whether to return :type as_custom_task: bool :param origin: task_origin if fetching from database (supported: {KernelBench, robust_kbench}) :type origin: str

load_kernelbench_task_from_csv(task_name, config)

Load KernelBench task from the pytorch functionals csv :param task_name: The name of the operation to get from the DB :type task_name: str :param config: config parameters

load_kernelbench_task_from_db(task_name, config)

Load KernelBench task from the Tasks table in the database :param task_name: The name of the operation to get from the DB :type task_name: str :param config: config to initialize the database :param origin: task_origin (supported: {KernelBench, robust_kbench}) :type origin: str

kernelfoundry.algorithm.utils.kernelbench_dataset.init_pytorch_functionals()[source]

Load functionals csv if not yet in memory

kernelfoundry.algorithm.utils.kernelbench_dataset.load_kernelbench_task_from_csv(task_name: str, config: DictConfig) str[source]

Load KernelBench task from the pytorch functionals csv :param task_name: The name of the operation to get from the DB :type task_name: str :param config: config parameters

Returns:

reference code

Return type:

str

kernelfoundry.algorithm.utils.kernelbench_dataset.load_kernelbench_task_from_db(task_name: str, config: DictConfig, origin: str = 'KernelBench') str[source]

Load KernelBench task from the Tasks table in the database :param task_name: The name of the operation to get from the DB :type task_name: str :param config: config to initialize the database :param origin: task_origin (supported: {KernelBench, robust_kbench}) :type origin: str

Returns:

reference code

Return type:

str

kernelfoundry.algorithm.utils.kernelbench_dataset.create_custom_task_files(tmpdir: str, config: DictConfig, task_name: str, reference: str, level: int)[source]

Fill the KernelBench template with the given reference and config and other info, copy to tmpdir

Parameters:
  • tmpdir (str) – path to temporary directory to which the files will be copied

  • config (DictConfig) – configuration parameters

  • task_name (str) – name of the operation

  • reference (str) – reference code

  • level (int) – level of the operation

kernelfoundry.algorithm.utils.kernelbench_dataset.kernelbench_reference_to_custom_task(task_name: str, config: DictConfig, reference: str, level: int) Task[source]

Convert KernelBench task for Task object

kernelfoundry.algorithm.utils.kernelbench_dataset.load_kernelbench_task(config: DictConfig, task_name: str, from_db: bool = False, as_custom_task: bool = False, origin: str = 'KernelBench')[source]

Load KernelBench task either from database or csv file, return as string or as customTask :param config: config with job parameters :param task_name: name of the operation :type task_name: str :param from_db: if True, load from db (otherwise load from csv) :type from_db: bool :param as_custom_task: whether to return :type as_custom_task: bool :param origin: task_origin if fetching from database (supported: {KernelBench, robust_kbench}) :type origin: str

Returns:

task as str or Task

kernelfoundry.algorithm.utils.kernelbench_dataset.get_kernelbench_task_id(task_name: str)[source]

Get ID of KernelBench task from database

kernelfoundry.algorithm.utils.kernelbench_dataset.assign_problem_hash(problem_path: str) list[int][source]

Assign a unique hash to a problem in the dataset

kernelfoundry.algorithm.utils.kernelbench_dataset.get_id_to_name_mapping(level: int)[source]
kernelfoundry.algorithm.utils.kernelbench_dataset.get_problem_list_by_level(level: int)[source]
kernelfoundry.algorithm.utils.kernelbench_dataset.get_code_hash(problem_src: str) str[source]

Assign a unique hash to some piece of code Important to strip out the comments and whitespace as they are not functionally part of the code

kernelfoundry.algorithm.utils.kernelbench_dataset.get_kernelbench_subset(data_config)[source]

Construct task_set from configuration

kernelfoundry.algorithm.utils.kernelbench_dataset.get_robust_kbench_task_list(config: DictConfig) dict[source]

Get dictionary of available tasks for robust-kbench. :param config: general configuration (for db init)

Returns:

Dictionary of {Op_ID: task_name} with all tasks with origin robust_kbench

Return type:

dict