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

docs: add inference section #529

Merged
merged 10 commits into from
Sep 8, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Docs

- Add inference session in examples. ([#529](https://github.com/jina-ai/finetuner/pull/529))


## [0.5.2] - 2022-08-31

Expand Down
22 changes: 20 additions & 2 deletions docs/tasks/image-to-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@ What you can do for now is to call {meth}`~finetuner.run.Run.logs()` in the end

After the run has finished successfully, you can download the tuned model on your local machine:
```python
run.save_artifact('resnet-model')
artifact = run.save_artifact('resnet-model')
```
That's it! Now you have a fine-tuned model which is ready to be {ref}`integrated with the Jina ecosystem <integrate-with-jina>`.

## Inference

Now you saved the `artifact` into your host machine,
let's use the fine-tuned model to encode a new `Document`:

```python
import finetuner
from docarray import Document, DocumentArray
# Load model from artifact
model = finetuner.get_model(artifact=artifact)
# Prepare some text to encode, change the placeholder image uri to an image on your machine
test_da = DocumentArray([Document(uri='my-image.png')])
# Encoding will happen in-place in your `DocumentArray`
finetuner.encode(model=model, data=test_da)
print(test_da.embeddings)
```

That's it! If you want to integrate the fine-tuned model into your Jina Flow, please check out {ref}`integrated with the Jina ecosystem <integrate-with-jina>`.
32 changes: 30 additions & 2 deletions docs/tasks/text-to-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@ We have done the evaulation for you in the table below.

After the run has finished successfully, you can download the tuned model on your local machine:
```python
run.save_artifact('clip-model')
artifact = run.save_artifact('clip-model')
```
That's it! Now you have a fine-tuned model which is ready to be {ref}`integrated with the Jina ecosystem <integrate-with-jina>`.

## Inference

Now you saved the `artifact` into your host machine,
let's use the fine-tuned model to encode a new `Document`:

```python
import finetuner
from docarray import Document, DocumentArray
# Load model from artifact
model = finetuner.get_model(artifact=artifact, select_model='clip-text')
# Prepare some text to encode
test_da = DocumentArray([Document(text='some text to encode')])
# Encoding will happen in-place in your `DocumentArray`
finetuner.encode(model=model, data=test_da)
print(test_da.embeddings)
```

```{admonition} what is select_model?
:class: hint
When fine-tuning CLIP, we are fine-tuning the CLIPVisionEncoder and CLIPTextEncoder in parallel.
The artifact contains two models: `clip-vision` and `clip-text`.
The parameter `select_model` tells finetuner which model to use for inference, in the above example,
we use `clip-text` to encode a Document with text content.
```

Check out [clip-as-service](https://clip-as-service.jina.ai/user-guides/finetuner/?highlight=finetuner#fine-tune-models) to learn how to plug-in a finetuned CLIP model to our CLIP specific service.

That's it! If you want to integrate the fine-tuned model into your Jina Flow, please check out {ref}`integrated with the Jina ecosystem <integrate-with-jina>`.
22 changes: 20 additions & 2 deletions docs/tasks/text-to-text.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,24 @@ print(f'Run logs: {run.logs()}')
## Saving
Once your run has successfully completed, you can save your fine-tuned model in the following way:
```python
run.save_artifact('bert-model')
artifact = run.save_artifact('bert-model')
```
That's it! Now you have a fine-tuned model which is ready to be {ref}`integrated with the Jina ecosystem <integrate-with-jina>`.

## Inference

Now you saved the `artifact` into your host machine,
let's use the fine-tuned model to encode a new `Document`:

```python
import finetuner
from docarray import Document, DocumentArray
# Load model from artifact
model = finetuner.get_model(artifact=artifact)
# Prepare some text to encode
test_da = DocumentArray([Document(text='some text to encode')])
# Encoding will happen in-place in your `DocumentArray`
finetuner.encode(model=model, data=test_da)
print(test_da.embeddings)
```

That's it! If you want to integrate the fine-tuned model into your Jina Flow, please check out {ref}`integrated with the Jina ecosystem <integrate-with-jina>`.
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

@pytest.fixture(autouse=True)
def overwrite_hubble_registry():
os.environ['JINA_FINETUNER_REGISTRY'] = 'https://api-staging.finetuner.fit'
os.environ['JINA_HUBBLE_REGISTRY'] = 'https://apihubble.staging.jina.ai'
os.environ['JINA_FINETUNER_REGISTRY'] = 'https://api.finetuner.fit'
os.environ['JINA_HUBBLE_REGISTRY'] = 'https://api.hubble.jina.ai'
yield
del os.environ['JINA_HUBBLE_REGISTRY']
del os.environ['JINA_FINETUNER_REGISTRY']