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

added next-steps.md #156

Merged
merged 3 commits into from Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
247 changes: 247 additions & 0 deletions docs/src/docs/next-steps.md
@@ -0,0 +1,247 @@
# Next Steps with Kit

In this guide you'll learn how to:
* Make your own Kitfile
* The power of `unpack`
* Read the Kitfile or manifest from a ModelKit
* Tag ModelKits and keep your registry tidy

## Making your own Kitfile

A Kitfile is the configuration document for your ModelKit. It's written in YAML so it's easy to read. There are four main parts to a Kitfile:
1. The `package` section: Metadata about the ModelKit, including the author, description, and license
1. The `code` section: Path to any codebases related to the project, including Jupyter notebook folders
1. The `datasets` section: Path to any datasets
1. The `model` section: Path to the serialized model

A Kitfile only needs the `package` section, plus one of the other sections.

The `datasets` and `code` sections can include multiple assets, but the `model` section can only contain a single model (you can chain models by using multiple ModelKits).

Here's an example Kitfile:

```yaml
manifestVersion: v1.0.0

package:
authors:
- Jozu
description: Small language model based on Mistral-7B fine tuned for answering film photography questions.
license: Apache-2.0
name: FilmSLM

model:
description: Film photography Q&A model using Mistral-7B
framework: Mistral-7B
license: Apache-2.0
name: FilmSLM
path: ./models/film_slm:champion
version: 1.2.6

datasets:
- description: Forum postings from sites like rangefinderforum, DPreview, PhotographyTalk, and r/AnalogCommunity
name: training data
path: ./data/forum-to-2023-train.csv
- description: validation data
name: validation data
path: ./data/test.csv

code:
- description: Jupyter notebook with model training code in Python
path: ./notebooks
```

A minimal ModelKit for distributing a pair of datasets might look like this:
```yaml
manifestVersion: v1.0.0

datasets:
- name: training data
path: ./data/train.csv
- description: validation data
name: validation data
path: ./data/validate.csv
```

Once you've authored a Kitfile for your AI/ML project you can pack it up and store it in your local or remote repository.

If you don't provide a registry Kit assumes you're operating against your local registry. For example:

```sh
kit pack . -t film-slm:champion
```

Will create a new tag `champion` in the `film-slm` repository in your local registry.

If you want to push to a remote registry there are two steps - tagging then pushing. Let's imagine we want to push our `champion` tag to Docker Hub:

First, you need to tag the image in your local registry with the remote registry's name:

```sh
kit pack . -t docker.io/jozubrad/film-slm:champion
```

Second, you push your local image to the remote registry:

```sh
kit push docker.io/jozubrad/film-slm:champion
bmicklea marked this conversation as resolved.
Show resolved Hide resolved
```

# The power of unpack

Models and their datasets can be very large and take a long time to push or pull, so Kit includes the `unpack` command that allows you to pull only pieces of the ModelKit you need, saving time and storage space:

`unpack` can take arguments for partial pulling of a ModelKit:
* `--model` to pull only the model to the destination file system
* `--datasets` to pull only the datasets to the destination file system
* `--code` to pull only the code bases to the destination file system
* `--config` to pull only the `Kitfile` to the destination file system

For example:

```sh
kit unpack mymodel:challenger --model -d ./model
```

Will extract the model from the `mymodel:challenger` ModelKit and place it in a local directory called `/model`.

The `unpack` command is part of the typical push and pull commands:
* `pack` will pack up a set of assets into a ModelKit package.
* `push` will push the whole ModelKit to a registry.
* `pull` will pull the whole ModelKit from a registry.
* `unpack` will extract all the assets from the ModelKit package.

## Read the Kitfile or manifest from a ModelKit

For any ModelKit in your local or remote registry you can easily read the Kitfile without pulling or unpacking it. This is a great way to understand what's in a ModelKit you might be interested in without needing to execute the more time-consuming unpack/pull comamnds.


```sh
kit info mymodel:challenger
```

Will print the following to your terminal:

```sh
manifestVersion: v1.0.0
package:
name: Finetuning_SLM
description: This Kitfile contains all the necessary files required for finetuning SLM.
license: Apache-2.0
authors: [Rajat]
model:
name: keras Model
path: ./model_adapter
framework: Scikit-learn
version: 1.0.0
description: Flight satisfaction and trait analysis model using Scikit-learn
license: Apache-2.0
code:
- path: ./SLM_Finetuning.ipynb
description: Jupyter notebook with model training code in Python
datasets:
- name: training data
path: ./slm_tuning_dataset.csv
description: UCF Video Dataset
```

If you need more details, like the size or file format of the contents, you can print the manifest to the terminal using the inspect command:

```sh
kit inspect mymodel:challenger
```

```sh
{
"schemaVersion": 2,
"config": {
"mediaType": "application/vnd.kitops.modelkit.config.v1+json",
"digest": "sha256:58444ef30d1cc7ee0fd2a24697e26252c38bf4317bfc791cd30c5af0d6f91f8f",
"size": 619
},
"layers": [
{
"mediaType": "application/vnd.kitops.modelkit.code.v1.tar+gzip",
"digest": "sha256:144ad8a89c3946ab794455450840f1b401511cdd8befc95884826376ef56d861",
"size": 12657
},
{
"mediaType": "application/vnd.kitops.modelkit.dataset.v1.tar+gzip",
"digest": "sha256:7d0f8d60895bba5c56e032f509c92553cfba1b014eee58f01e46d7af923099e8",
"size": 13787789
},
{
"mediaType": "application/vnd.kitops.modelkit.model.v1.tar+gzip",
"digest": "sha256:25646107e93d62ccd55b2cf14dfd55f7bbf426e5492a42d3d7f1bfd2cde30035",
"size": 122
}
]
}
```

## Tag ModelKits and keep your registry tidy

Tagging is a great way to version your ModelKits as they move through the development lifecycle. For example, during development the model I'm working on currently may always be tagged as the `latest` so my team knows which is most current. At the same time the model that's operating in production for my customers may be tagged the `champion`.

However, after testing my latest model, I find that its scores are much higher than the current champion model. At that point I may want to tag it `challenger` so everyone knows that this is likely to be the next model we deploy to production, to replace our current champion model.

To do that I can simply add a new tag based on the existing latest tag.

```sh
kit tag mymodel:latest mymodel:challenger
```

If you run `kit list` you'll now see that you have two models in your local registry:

```sh
kit list

REPOSITORY TAG MAINTAINER NAME SIZE DIGEST
mymodel latest Rajat Finetuning_SLM 13.1 MiB sha256:f268a74ff85a00f2a68400dfc17b045bc7c1638da7f096c7ae400ad5bdfd520c

mymodel challenger Rajat Finetuning_SLM 13.1 MiB sha256:f268a74ff85a00f2a68400dfc17b045bc7c1638da7f096c7ae400ad5bdfd520c
```

You'll notice that the digest of the two ModelKits is the same so while you have two tags, the ModelKit itself is only stored once for efficiency. This makes tags an efficient way to mark models that have hit specific milestones that are meaningful to your organization's development lifecycle.

Now let's imagine that we deploy our challenger model. At that point we'd tag it as `champion`:

```sh
kit tag mymodel:challenger mymodel:champion
```

If you run `kit list` you'll now see that you have two models in your local registry:

```sh
kit list

REPOSITORY TAG MAINTAINER NAME SIZE DIGEST
mymodel latest Rajat Finetuning_SLM 13.1 MiB sha256:f268a74ff85a00f2a68400dfc17b045bc7c1638da7f096c7ae400ad5bdfd520c

mymodel challenger Rajat Finetuning_SLM 13.1 MiB sha256:f268a74ff85a00f2a68400dfc17b045bc7c1638da7f096c7ae400ad5bdfd520c

mymodel champion Rajat Finetuning_SLM 13.1 MiB sha256:f268a74ff85a00f2a68400dfc17b045bc7c1638da7f096c7ae400ad5bdfd520c
```

Now we no longer want this ModelKit to be tagged as `challenger` because it's the `champion` so we can remove it from our registry:

```sh
kit remove mymodel:challenger

Removed localhost/mymodel:challenger (digest sha256:f268a74ff85a00f2a68400dfc17b045bc7c1638da7f096c7ae400ad5bdfd520c)
```

Running kit list again will show our updated local registry contents:

```sh
kit list

REPOSITORY TAG MAINTAINER NAME SIZE DIGEST
mymodel latest Rajat Finetuning_SLM 13.1 MiB sha256:f268a74ff85a00f2a68400dfc17b045bc7c1638da7f096c7ae400ad5bdfd520c

mymodel champion Rajat Finetuning_SLM 13.1 MiB sha256:f268a74ff85a00f2a68400dfc17b045bc7c1638da7f096c7ae400ad5bdfd520c
```

You can learn more about all the Kit CLI commands from our [command reference doc](./cli/cli-reference.md).

Thanks for taking some time to play with Kit. We'd love to hear what you think. Feel free to drop us an [issue in our GitHub repository](https://github.com/jozu-ai/kitops/issues) or join [our Discord server](https://discord.gg/YyAfWnEg).
6 changes: 6 additions & 0 deletions docs/src/docs/quick-start.md
Expand Up @@ -109,4 +109,10 @@ You've learned how to unpack a ModelKit, pack one up, and push it. Anyone with a
kit pull docker.io/jozubrad/mymodelkit:latest
```

If you'd like to learn more about using Kit, try our [Next Steps with Kit](./next-steps.md) document which will cover:
* Making your own Kitfile
* The power of `unpack`
* Tagging ModelKits
* Keeping your registry tidy

Thanks for taking some time to play with Kit. We'd love to hear what you think. Feel free to drop us an [issue in our GitHub repository](https://github.com/jozu-ai/kitops/issues) or join [our Discord server](https://discord.gg/YyAfWnEg).