Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profiling documentation #536

Merged
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
Binary file added docs/assets/nos_catalog_t4_complete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions docs/cli/profile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## ⏱️ Profiling Models

`nos profile` supports model benchmarking across a number of axes including iterations per second,
memory footprint and utilization on CPU/GPU.
Currently, the nos profiler itself runs natively in the execution environment (i.e. outside
the NOS server), so you'll need to install both the `server` and `test` dependencies alongside
your existing NOS installation.

```bash
pip install torch-nos[server,test]
```

Copy link
Contributor

@spillai spillai Jan 31, 2024

Choose a reason for hiding this comment

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

It might be helpful to break this README by subcommand:

First, can you print the output of nos profile --help here so that the users can see the relevant subcommands supported?

Then you can have different sections such as

nos profile rebuild-catalog

...

nos profile method -m <model-id>

nos profile method -t <model-type>

## NOS Profile Commands

### all
Profile all models

If you have the time, you can construct a profiling catalog on your machine in its entirety with:
```bash
nos profile all
```
### rebuild-catalog
Generate a fresh catalog with
```bash
nos profile rebuild-catalog
```
### model
You can also profile specific models with
```bash
nos profile model -m openai/clip-vit-large-patch14
```
### method
Or an entire method type with
```bash
nos profile method -m encode_image
Copy link
Contributor

Choose a reason for hiding this comment

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

Are method type and method names interchangeable here with -m flag? Wouldn't we want them to have a different flag? -m for model name and -t for method type?

```
to benchmark e.g. all image embedding models.

### list
Dump the nos profiling catalog with `nos profile list`

![NOS Profile List](../assets/nos_catalog_t4_complete.png)
23 changes: 17 additions & 6 deletions nos/common/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,19 +433,30 @@ def load(self, model_method_id: Any) -> "ModelSpec":

def load_profile_catalog(self) -> "ModelSpecMetadataCatalog":
"""Load the model profiles from a JSON catalog."""
import logging
import os
from pathlib import Path

import pandas as pd

if not NOS_PROFILE_CATALOG_PATH.exists():
raise FileNotFoundError(f"Model metadata catalog not found, path={NOS_PROFILE_CATALOG_PATH}.")
logger = logging.getLogger(__name__)

import logging
catalog_path = NOS_PROFILE_CATALOG_PATH

logger = logging.getLogger(__name__)
debug_str = "Loading profiling catalog from " + str(NOS_PROFILE_CATALOG_PATH)
# Check if we have NOS_PROFILE_CATALOG_PATH_OVERRIDE in the environment
if os.environ.get("NOS_PROFILE_CATALOG_PATH_OVERRIDE"):
catalog_path = Path(os.environ["NOS_PROFILE_CATALOG_PATH_OVERRIDE"])
logger.debug(f"Using custom profile catalog [path={catalog_path}]")

if not catalog_path.exists():
# Make sure the catalog (either default or custom) exists
raise FileNotFoundError(f"Model metadata catalog not found, path={catalog_path}.")

debug_str = "Loading profiling catalog from " + str(catalog_path)
logger.info(debug_str)

# Read the catalog
df = pd.read_json(str(NOS_PROFILE_CATALOG_PATH), orient="records")
df = pd.read_json(str(catalog_path), orient="records")
columns = df.columns
# Check if the catalog is valid with the required columns

Expand Down
Loading