Optimization effort#978
Conversation
PR Reviewer Guide 🔍(Review updated until commit 3e20a37)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 3e20a37
Previous suggestionsSuggestions up to commit 1018a69
|
|
Persistent review updated to latest commit 3e20a37 |
| def create_worktree_root_dir(module_root: Path) -> tuple[Path | None, Path | None]: | ||
| git_root = git_root_dir() if check_running_in_git_repo(module_root) else None | ||
| worktree_root_dir = Path(tempfile.mkdtemp()) if git_root else None | ||
| return git_root, worktree_root_dir | ||
|
|
||
|
|
||
| def create_git_worktrees( | ||
| git_root: Path | None, worktree_root_dir: Path | None, module_root: Path | ||
| ) -> tuple[Path | None, list[Path]]: | ||
| if git_root and worktree_root_dir: | ||
| worktree_root = Path(tempfile.mkdtemp(dir=worktree_root_dir)) | ||
| worktrees = [Path(tempfile.mkdtemp(dir=worktree_root)) for _ in range(N_CANDIDATES_EFFECTIVE + 1)] | ||
| for worktree in worktrees: | ||
| subprocess.run(["git", "worktree", "add", "-d", worktree], cwd=module_root, check=True) | ||
| else: | ||
| worktree_root = None | ||
| worktrees = [] | ||
| return worktree_root, worktrees | ||
|
|
||
|
|
||
| def remove_git_worktrees(worktree_root: Path | None, worktrees: list[Path]) -> None: | ||
| try: | ||
| for worktree in worktrees: | ||
| subprocess.run(["git", "worktree", "remove", "-f", worktree], check=True) | ||
| except subprocess.CalledProcessError as e: | ||
| logger.warning(f"Error removing worktrees: {e}") | ||
| if worktree_root: | ||
| shutil.rmtree(worktree_root) | ||
|
|
||
|
|
There was a problem hiding this comment.
old unused methods
…zation params with effort
|
@mohammedahmed18 unit tests failing |
|
@aseembits93 looking into it now |
|
@mohammedahmed18 looks like this needs to be updated |
| "is_async": is_async, | ||
| "lsp_mode": is_LSP_enabled(), | ||
| "call_sequence": self.get_next_sequence(), | ||
| "n_candidates": n_candidates, |
There was a problem hiding this comment.
backwards api endpoint compatibility should be fine, you can confirm it
There was a problem hiding this comment.
Yep, I did set default values in the aiservice
|
why is n_candidates needed? I thought we were handling all that in the backend? |
| MAX_CONTEXT_LEN_REVIEW = 1000 | ||
|
|
||
|
|
||
| class EffortLevel(str, Enum): |
There was a problem hiding this comment.
this way is fine, another way of setting these things is via a yaml file, you could have multiple of them with different combinations of parameters. it's a subjective opinion, this way of implementation is also fine.
There was a problem hiding this comment.
Yaml makes more sense for configurations, will implement it in a separate PR, and maybe move the rest of config values to yaml not just effort-related
There was a problem hiding this comment.
Yaml makes more sense for configurations, will implement it
|
@KRRT7 the backend can now accept the number of candidates and will use the number to create the model distribution like this It will generat 2 with gpt and 1 with sonnet |
yes and look at how we're doing model distribution for optimizer in the backend |
|
aiservice/optimizer/config.py |
User description
depends on https://github.com/codeflash-ai/codeflash-internal/pull/2191
fixes CF-959
PR Type
Enhancement
Description
Introduce effort-based optimization controls
Replace fixed constants with dynamic effort values
Add CLI flag for effort selection
Align API payload keys and defaults
Diagram Walkthrough
File Walkthrough
aiservice.py
Align API payload keys and candidate defaultscodeflash/api/aiservice.py
n_candidatesandn_candidates_lpcli.py
Add CLI effort level optioncodeflash/cli_cmds/cli.py
--effortCLI flagconfig_consts.py
Introduce effort-based configuration systemcodeflash/code_utils/config_consts.py
EffortLevel,EffortKeys, and values mapget_effort_valuehelpergit_utils.py
Remove worktree utilities and tidy importscodeflash/code_utils/git_utils.py
function_optimizer.py
Apply effort-based tuning throughout optimizercodeflash/optimization/function_optimizer.py
get_effort_valueacross flows