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

Preload / Prewarm custom models via URL on startup #475

Merged
merged 11 commits into from
May 16, 2023

Conversation

vicilliar
Copy link
Contributor

@vicilliar vicilliar commented May 12, 2023

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    Feature

  • What is the current behavior? (You can also link to an open issue here)
    Currently, the env var only accepts strings.

  • What is the new behavior (if this is a feature change)?
    This allows the env var MARQO_MODELS_TO_PRELOAD to accept custom models as dicts with model and model_properties. A sample declaration would look like this:

export MARQO_MODELS_TO_PRELOAD='[
        "ViT-L/14",
         {
            "model": "generic-clip-test-model-2",
            "model_properties": {
                "name": "ViT-B/32",
                "dimensions": 512,
                "type": "clip",
                "url": "https://openaipublic.azureedge.net/clip/models/40d365715913c9da98579312b702a82c18be219cc2a73407c4526f58eba950af/ViT-B-32.pt"
            }
        }
    ]'
  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
    No

  • Have unit tests been run against this PR? (Has there also been any additional testing?)
    Manual testing. Application tests will be made once the env var customization feature in Marqo API tests finishes

  • Related documentation changes (link commit/PR here)
    To follow

  • Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes/features)
  • Docs have been added / updated (for bug fixes / features)

@vicilliar
Copy link
Contributor Author

Manual testing matrix (OPEN CLIP and CLIP only so far)

Please let me know if there are other important edge cases to test
image

@vicilliar
Copy link
Contributor Author

Models used for said manual testing:
OPEN CLIP

{
            "model": "random-open-clip-1",
            "model_properties": {
                "name": "ViT-B-32-quickgelu",
                "dimensions": 512,
                "url": "https://github.com/mlfoundations/open_clip/releases/download/v0.2-weights/vit_b_32-quickgelu-laion400m_avg-8a00ab3c.pt",
                "type": "open_clip"
            }
        }

CLIP

{
            "model": "generic-clip-test-model-2",
            "model_properties": {
            	"name": "ViT-B/32",
                "dimensions": 512,
                "url": "https://openaipublic.azureedge.net/clip/models/40d365715913c9da98579312b702a82c18be219cc2a73407c4526f58eba950af/ViT-B-32.pt",
                "type": "clip"
            }
        }

@pandu-k pandu-k requested a review from wanliAlex May 15, 2023 02:34
@vicilliar vicilliar requested a review from pandu-k May 15, 2023 13:49
@vicilliar vicilliar changed the title Prewarm custom models via URL on startup Preload / Prewarm custom models via URL on startup May 15, 2023
@pandu-k
Copy link
Collaborator

pandu-k commented May 16, 2023

Thanks for the testing matrix!

Is the no "name" behaviour the same as when creating an index with this model normally? What is the expected behaviour @wanliAlex ?

@wanliAlex
Copy link
Collaborator

Thanks for the testing matrix!

Is the no "name" behaviour the same as when creating an index with this model normally? What is the expected behaviour @wanliAlex ?

Thanks for the testing matrix!

Is the no "name" behaviour the same as when creating an index with this model normally? What is the expected behaviour @wanliAlex ?

Yes, because "name" is not required for loading clip models, but we make it a required filed in model properties.

@wanliAlex
Copy link
Collaborator

Do we want to hold this PR for a while until my custom HF models are merged? Do we want to test the custom HF models prewarming?

@wanliAlex
Copy link
Collaborator

The name check is here

But note that the "name" is not used for clip models if a URL is provided.

@vicilliar
Copy link
Contributor Author

Do we want to hold this PR for a while until my custom HF models are merged? Do we want to test the custom HF models prewarming?

I'm under the impression this URL pre-warming feature is high priority, so it can be merged asap, but I'll need confirmation from @pandu-k

If ever, do we see the format for HF/S3 models being much different? Or are they also in the form model and model_properties?

@wanliAlex
Copy link
Collaborator

Do we want to hold this PR for a while until my custom HF models are merged? Do we want to test the custom HF models prewarming?

I'm under the impression this URL pre-warming feature is high priority, so it can be merged asap, but I'll need confirmation from @pandu-k

If ever, do we see the format for HF/S3 models being much different? Or are they also in the form model and model_properties?

Yeah they are similar. Feel free to merge if it's urgent as this is for production use.

@pandu-k
Copy link
Collaborator

pandu-k commented May 16, 2023

Let's get this merged in first, so we can spin up a testing tag

@wanliAlex
Copy link
Collaborator

The PR looks good to me. Just to confirm, did you do the manual test on a dockerised marqo? @vicilliar

@vicilliar
Copy link
Contributor Author

Ah good idea, i have not yet. Will do so

@vicilliar
Copy link
Contributor Author

I did the tests on a local running marqo

@wanliAlex
Copy link
Collaborator

I did the tests on a local running marqo

Can you try to run several manual tests on a dockerised marqo and upload some screenshots? Would this be enough to test the production environment? @pandu-k

@pandu-k
Copy link
Collaborator

pandu-k commented May 16, 2023

That should be pretty good. Try expected failure and expected successful cases. Ensure that search/add docs works as expected. The testing matrix was super useful

return True
assert run()

# TODO: test bad/no names/URLS in end-to-end tests, as this logic is done in vectorise call

Copy link
Collaborator

Choose a reason for hiding this comment

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

can we have one more test to ensure the prewarmed model will not need to be download/load again?

Copy link
Collaborator

Choose a reason for hiding this comment

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

can we have one more test to ensure the prewarmed model will not need to be download/load again?

For both search and add_document.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this we can save for the API end-to-end test

@pandu-k
Copy link
Collaborator

pandu-k commented May 16, 2023

@pandu-k pandu-k temporarily deployed to marqo-test-suite May 16, 2023 05:30 — with GitHub Actions Inactive
@pandu-k pandu-k temporarily deployed to marqo-test-suite May 16, 2023 05:30 — with GitHub Actions Inactive
@vicilliar
Copy link
Contributor Author

vicilliar commented May 16, 2023

failing 1 unit test on local:
This is probably just an existing problem, unit tests through GH actions work just fine

marqo.errors.BadRequestError: BadRequestError: Problem vectorising query. Reason: Unable to load model=ViT-B/16 on device=cpu with normalization=True. If you are trying to load a custom model, please check that model_properties={'name': 'ViT-B/16', 'dimensions': 512, 'notes': 'CLIP ViT-B/16', 'type': 'clip'} is correct and Marqo has access to the weights file.
============================================== short test summary info ==============================================
FAILED tests/tensor_search/test_add_documents.py::TestAddDocuments::test_mappings_arent_updated_images - marqo.errors.BadRequestError: BadRequestError: Problem vectorising query. Reason: Unable to load model=ViT-B/16 ...

@vicilliar
Copy link
Contributor Author

Dockerized manual marqo testing:
works as expected (open clip).

  1. Startup loads the models properly (hf model and a custom open clip model)
    image

  2. Upon indexing, no preloading is done (expected)
    image

  3. Search works fine, here is a sample query result for q="vegetable"

{'hits': [{'field_1': 'cabbage', '_id': '3', '_highlights': {'field_1': 'cabbage'}, '_score': 0.87822014}, {'field_1': 'red', '_id': '2', '_highlights': {'field_1': 'red'}, '_score': 0.8071192}, {'field_1': 'hello', '_id': '1', '_highlights': {'field_1': 'hello'}, '_score': 0.80202985}], 'query': 'vegetable', 'limit': 10, 'offset': 0, 'processingTimeMs': 284}

Here is the indexing/searching script used

import marqo
mq = marqo.Client()
settings = {
    "index_defaults": {
        "treat_urls_and_pointers_as_images": True,
        "model": 'generic-clip-test-model-1',
        "model_properties": {
            "name": "ViT-B-32-quickgelu",
                "dimensions": 512,
                "url": "https://github.com/mlfoundations/open_clip/releases/download/v0.2-weights/vit_b_32-quickgelu-laion400m_avg-8a00ab3c.pt",
                "type": "open_clip"
            },
        "normalize_embeddings": True,
    },
}
try:
    mq.delete_index("my-own-clip")
except:
    pass

response = mq.create_index("my-own-clip", settings_dict=settings)

mq.index("my-own-clip").add_documents(
    [
        {"_id": "1", "field_1": "hello"}, 
        {"_id": "2", "field_1": "red"}, 
        {"_id": "3", "field_1": "cabbage"}, 
    ]
)
res = mq.index("my-own-clip").search("vegetable")
print("search results are: ")
print(res)

@vicilliar
Copy link
Contributor Author

vicilliar commented May 16, 2023

Failure cases are also as expected:

Malformed JSON result:
image

Missing model result:
image

Missing model_properties result:
image

Also there are some mistakes in the error message, so I'm pushing a small change, just changing the message to this:
image

@pandu-k pandu-k merged commit fb8d22d into mainline May 16, 2023
@pandu-k pandu-k deleted the joshua/prewarm-any-model branch May 16, 2023 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants