kernelfoundry.algorithm.utils.extract_code¶
Functions
|
Apply a diff to the original code |
|
Extract all code blocks from text, combine them to return as a single string |
|
Extracts code either from codeblocks, from string, or from tags |
|
|
|
Extract C++ code from model output |
|
Extract diff blocks from the diff text |
|
Extract first code block from model output, specified by code_language_type |
|
Extract last code block from model output, specified by code_language_type |
|
Extract python code from model output |
|
Create a human-readable summary of the diff |
|
Assume input is code but just with like python, cpp, etc. |
|
For templated kernels, add template_args to pytorch functional |
- kernelfoundry.algorithm.utils.extract_code.extract_python_code(text)[source]¶
Extract python code from model output
- kernelfoundry.algorithm.utils.extract_code.remove_code_block_header(code, code_language_type)[source]¶
Assume input is code but just with like python, cpp, etc. at the top
- kernelfoundry.algorithm.utils.extract_code.extract_first_code(output_string: str, code_language_types: list[str]) str[source]¶
Extract first code block from model output, specified by code_language_type
- kernelfoundry.algorithm.utils.extract_code.extract_code_flexible(output_string: str, tag: str = 'cuda', use_first: bool = False, code_language_types: list = ['cuda', 'sycl', 'python', 'cpp', 'triton', 'ocl']) str | None[source]¶
Extracts code either from codeblocks, from string, or from tags
- kernelfoundry.algorithm.utils.extract_code.extract_cpp_code_heuristic(output_string: str) str | None[source]¶
Extract C++ code from model output
- kernelfoundry.algorithm.utils.extract_code.extract_code_from_tags(output_string: str, tag: str = 'cuda', use_first: bool = False, code_language_types: list = ['cuda', 'sycl', 'python', 'cpp', 'triton', 'ocl']) str | None[source]¶
- kernelfoundry.algorithm.utils.extract_code.extract_last_code(output_string: str, code_language_types: list[str]) str | None[source]¶
Extract last code block from model output, specified by code_language_type
- kernelfoundry.algorithm.utils.extract_code.extract_code_blocks(text, code_language_types: list[str]) str[source]¶
Extract all code blocks from text, combine them to return as a single string
- kernelfoundry.algorithm.utils.extract_code.apply_diff(original_code: str, diff_text: str) str[source]¶
Apply a diff to the original code
- Parameters:
original_code – Original source code
diff_text – Diff in the SEARCH/REPLACE format
- Returns:
Modified code
- kernelfoundry.algorithm.utils.extract_code.extract_diffs(diff_text: str) List[Tuple[str, str]][source]¶
Extract diff blocks from the diff text
- Parameters:
diff_text – Diff in the SEARCH/REPLACE format
- Returns:
List of tuples (search_text, replace_text)