-
Notifications
You must be signed in to change notification settings - Fork 66
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
Changes from 5 commits
edbe932
877ca07
dc843dd
8df2196
36c02f7
6af2f3d
3a90e88
fe4358f
a5a874a
74c7c08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 fine-tuned model to encode a new `Document`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the |
||||||
|
||||||
```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 fine-tuned model into your Jina Flow, please check out {ref}`integrated with the Jina ecosystem <integrate-with-jina>`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. integrate the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 fine-tuned model to encode a new `Document`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the fine-tuned model There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```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 finetune which model to use for inference, in the above example, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. finetuner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
we use `clip-text` to encode a Document with text. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with text content |
||||||
``` | ||||||
|
||||||
Check out [clip-as-service](https://clip-as-service.jina.ai/user-guides/finetuner/?highlight=finetuner#fine-tune-models) to know how to plug-in fine-tuned model there. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to learn how to plug-in a finetuned CLIP model to our CLIP specific service. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
That's it! If you want to integrate fine-tuned model into your Jina Flow, please check out {ref}`integrated with the Jina ecosystem <integrate-with-jina>`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. integrate the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 fine-tuned model to encode a new `Document`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```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 fine-tuned model into your Jina Flow, please check out {ref}`integrated with the Jina ecosystem <integrate-with-jina>`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. integrate the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.