Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions docs/docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ This is a great way to ensure that your code, your team's code and your AI Agent

<!--- TODO: Add links to the relevant sections of the documentation and style the table --->

| Feature | Description |
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Optimize a single function](optimizing-with-codeflash/one-function) | `codeflash --file path.py --function myfunctionpy` Basic unit of optimization by asking Codeflash to optimize a particular function
| [Optimize an entire workflow](optimizing-with-codeflash/trace-and-optimize) | `codeflash optimize myscript.py` End to end optimization for all the functions called in a workflow, by tracing to collect real inputs to ensure correctness and e2e performance optimization |
| [Optimize all code in a repo](optimizing-with-codeflash/codeflash-all) | `codeflash --all` Codeflash discovers all functions in a repo and optimizes all of them! |
| [Optimize every new pull request](optimizing-with-codeflash/optimize-prs) | `codeflash init-actions` Codeflash runs as a GitHub action and GitHub app and reviews all new code for Optimizations |
| Feature | Usage | Description |
|------------------------------------------------------------------------------|---------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Optimize a single function](optimizing-with-codeflash/one-function) | `codeflash --file path.py --function my_function` | Basic unit of optimization by asking Codeflash to optimize a particular function |
| [Optimize an entire workflow](optimizing-with-codeflash/trace-and-optimize) | `codeflash optimize myscript.py` | End to end optimization for all the functions called in a workflow, by tracing to collect real inputs to ensure correctness and e2e performance optimization |
| [Optimize all code in a repo](optimizing-with-codeflash/codeflash-all) | `codeflash --all` | Codeflash discovers all functions in a repo and optimizes all of them! |
| [Optimize every new pull request](optimizing-with-codeflash/optimize-prs) | `codeflash init-actions` | Codeflash runs as a GitHub action and GitHub app and suggests optimizations for all new code in a Pull Request. |


## How to use these docs

On the left side of the screen you'll find the docs navigation bar.
On the left side of the screen, you'll find the docs navigation bar.
Start by installing Codeflash, then explore the different ways of using it to optimize your code.

## Questions or Feedback?

We love feedback! If you have any questions or feedback, use the Intercom button in the lower right, join our [Discord](https://www.codeflash.ai/discord), or drop us a note at [[email protected]](mailto:[email protected]) - we read every message!
Your feedback will help us make codeflash better, faster. If you have any questions or feedback, use the Intercom button in the lower right, join our [Discord](https://www.codeflash.ai/discord), or drop us a note at [[email protected]](mailto:[email protected]) - we read every message!
20 changes: 10 additions & 10 deletions docs/docs/optimizing-with-codeflash/trace-and-optimize.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ To optimize a script, `python myscript.py`, replace `python` with `codeflash opt
codeflash optimize myscript.py
```

To optimize code within pytest tests that you normally run like `python -m pytest tests/`, use this command:
To optimize code within pytest tests that you could normally run like `python -m pytest tests/`, use this command:

```bash
codeflash optimize -m pytest tests/
```

This powerful command creates high-quality optimizations, making it ideal when you need to optimize a workflow or script. The initial tracing process is slow, so try to limit your script's runtime to under 1 minute for best results. If your workflow is longer, consider breaking it into smaller sections and optimizing them separately with limited but representative data.
This powerful command creates high-quality optimizations, making it ideal when you need to optimize a workflow or script. The initial tracing process can be slow, so try to limit your script's runtime to under 1 minute for best results. If your workflow is longer, consider tracing it into smaller sections by using the Codeflash tracer as a context manager (point 3 below).

## What is the codeflash optimize command?

`codeflash optimize` does everything that an expert engineer would do while optimizing a workflow. It profiles your code, traces the execution of your workflow and generates a set of test cases that are derived from how your code is actually run.
`codeflash optimize` tries to do everything that an expert engineer would do while optimizing a workflow. It profiles your code, traces the execution of your workflow and generates a set of test cases that are derived from how your code is actually run.
Codeflash Tracer works by recording the inputs of your functions as they are called in your codebase. These inputs are then used to generate test cases that are representative of the real-world usage of your functions.
We call these generated test cases "Replay Tests" because they replay the inputs that were recorded during the tracing phase.

Then, Codeflash Optimizer can use these replay tests to verify correctness and calculate accurate performance gains for the optimized functions.
Using Replay Tests, Codeflash can verify that the optimized functions produce the same output as the original function and also measure the performance gains of the optimized function on the real-world inputs.
This way you can be *sure* that the optimized function causes no changes of behavior for the traced workflow and also, that it is faster than the original function.
This way you can be *sure* that the optimized function causes no changes of behavior for the traced workflow and also, that it is faster than the original function. To get more confidence on the correctness of the code, we also generate several LLM generated test cases and discover any existing unit cases you may have.

## Using codeflash optimize

Codeflash Tracer can be used in three ways:
Codeflash script optimizer can be used in three ways:

1. **As an integrated command**

Expand All @@ -47,7 +47,7 @@ Codeflash Tracer can be used in three ways:
codeflash optimize path/to/your/file.py --your_options
```

The above command should suffice in most situations. You can add a argument like `codeflash optimize -o trace_file_path.trace` if you want to customize the trace file location. Otherwise, it defaults to `codeflash.trace` in the cwd.
The above command should suffice in most situations. You can add a argument like `codeflash optimize -o trace_file_path.trace` if you want to customize the trace file location. Otherwise, it defaults to `codeflash.trace` in the current working directory.

2. **Trace and optimize as two separate steps**

Expand Down Expand Up @@ -76,18 +76,18 @@ Codeflash Tracer can be used in three ways:
from codeflash.tracer import Tracer

with Tracer(output="codeflash.trace"):
# Your code here
model.predict() # Your code here
```

Sometimes, if using the tracer as a module fails, then the Context Manager can also be used to trace the code sections. This also is much faster than tracing the whole script.
This is much faster than tracing the whole script. Sometimes, if tracing the whole script fails, then the Context Manager can also be used to trace the code sections.

After this finishes, you can optimize using the replay tests
After this finishes, you can optimize using the generated replay tests.

```bash
codeflash --replay-test /path/to/test_replay_test_0.py
```

More Options to the Tracer:
More Options for the Tracer:

- `disable`: If set to `True`, the tracer will not trace the code. Default is `False`.
- `max_function_count`: The maximum number of times to trace a single function. More calls to a function will not be traced. Default is 100.
Expand Down
Loading