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

Implement Model Switching Functionality in Inference Request #51

Closed
4 tasks done
CFIALeronB opened this issue Jan 24, 2024 · 3 comments · Fixed by #53 or #55
Closed
4 tasks done

Implement Model Switching Functionality in Inference Request #51

CFIALeronB opened this issue Jan 24, 2024 · 3 comments · Fixed by #53 or #55
Assignees

Comments

@CFIALeronB
Copy link

CFIALeronB commented Jan 24, 2024

Issue Description

The goal is to implement model switching functionality in the inference_request function, allowing it to handle different models based on the model_name parameter passed in the request. An issue arises when the system tries to access a model function that is not implemented, leading to an error.

Steps to Reproduce

  1. Send a request to the /inf endpoint with model_name set to a value that does not correspond to an implemented model function.
  2. The system attempts to access a function based on the model_name and fails if the function is not implemented.

Expected Behavior

The inference_request function should dynamically select and call the correct model processing function based on the model_name provided in the request. If a model_name is provided that does not have an associated processing function, the system should handle it gracefully.

Current Behavior

The system throws an error indicating that the required model processing function is not found in the model_inference.inference module when a non-implemented model_name is used.

Possible Solution

Implement a check within the inference_request function to ensure that the model_name provided in the request corresponds to an implemented model processing function. If not, the system should return a meaningful error message or default to a general processing function.

Additional Context

  • This issue is crucial for the scalability of the system, allowing new models to be integrated seamlessly.
  • The handling of different models should be modular and maintainable, avoiding complex conditional structures for each model.

Tasks

  • Verify the structure and implementation of the model_inference.inference module.
  • Implement a robust model selection mechanism in the inference_request function.
  • Ensure that the system gracefully handles cases where the model_name does not correspond to an implemented model processing function.
  • Update documentation and comments to reflect the new model switching functionality.
@CFIALeronB CFIALeronB self-assigned this Jan 24, 2024
@rngadam rngadam added this to Nachet Jan 24, 2024
@rngadam
Copy link

rngadam commented Jan 24, 2024

CFIALeronB added a commit that referenced this issue Jan 25, 2024
- Added model_name parameter handling in inference_request function.
- Created model_mapping dictionary to map model names to their respective processing functions.
- Integrated dynamic model selection based on the model_name parameter.
- Ensured consistent data structure for process_inference_results function across different models.

#51 #31
@CFIALeronB CFIALeronB linked a pull request Jan 25, 2024 that will close this issue
@MaxenceGui
Copy link

MaxenceGui commented Jan 29, 2024

Inference Request with n pipelines

Glossary

Pipelines

Pipelines are define as a set of models that follow each others where output of
one model is used as input for the next models. A pipeline contains from 1 to n
models.

flowchart LR

A{Pipeline entry point}-->|user input|SB1-->F{Pipeline exit point}-->|"last model
output"|G>"return
result.json to user"]

subgraph SB1[In pipeline]
    direction TB

    B(model 01)-->|"model output
    send to the next one"|C(model 02)-->|can have n models|D(n models)

end
Loading

Models

A model is a AI model who's part of a pipeline. A model accept images as input
and return json as output. Generally json contains coordinate of object in the
source image, that he may prompt out to feed the next step of the model.

Model from Frontend

On the frontend interface, a pipeline will be call a model, since the user will
not be aware of the difference. From the user perspective, he sent data to a
model and receive the result.

Suggestion: we could call the pipeline a method, if we don't want to mix term.

Sequence Diagram for inference request

sequenceDiagram

    actor Client
    participant Frontend
    participant Backend
    participant Blob storage
    participant Model

    Note over Backend,Blob storage: initialisation
    Backend-)Backend: before_serving()
    Backend-)Backend: get_pipelines_models()
    alt
    Backend-)Blob storage: HTTP POST req.
    Blob storage--)Backend: return pipelines_models.json
    else
    Backend-)Frontend: error 400 No pipeline found
    end
    Note over Backend,Blob storage: end of initialisation
   
    Client->>Frontend: applicationStart()
    Frontend-)Backend: HTTP POST req.
    Backend-)Backend: get_pipelines_names()
    Note right of Backend: return pipelines names set(pipelines.keys())
    Backend--)Frontend: Pipelines names res.

    Frontend->>Client: application is ready
    Client-->>Frontend: client ask action from specific pipeline
    Frontend-)Backend: HTTP POST req.
    Backend-)Backend: inference_request(pipeline_name, folder_name, container_name, imageDims, image)
    alt missing argument
        Backend--)Frontend: Error 400 missing arguments
    else no missing argument
        Backend-)Backend: mount_container(connection_string(Environnement Variable, container_name))
        Backend-)Blob storage: HTTP POST req.
        Blob storage--)Backend: container_client
        
        Backend-)Backend: upload_image(container_client, folder_name, image_bytes, hash_value)
        Backend-)Blob storage: HTTP POST req.
        Blob storage--)Backend: blob_name

        Backend-)Backend: get_blob(container_client, blob_name)
        Backend-)Blob storage: HTTP POST req.
        Blob storage--)Backend: blob

        loop for every model in pipeline
            Note over Backend,Blob storage: Need to build endpoint with pipeline_name
            Backend-)Backend: urllib.request.Request(endpoint_url, body, header)
            Backend-)Model: HTTP POST req.
            Model--)Backend: result.json
        end
        
        par Backend to Frontend
            Backend--)Frontend: Processed result res.
        and Backend to Blob storage
            Backend-)Backend: upload_inference_result(container_client, folder_name, result_json_string, hash_value)
            Backend-)Blob storage: HTTP POST req.
        end
    end
    Frontend--)Client: display result
Loading

footer_for_diagram

@rngadam
Copy link

rngadam commented Jan 29, 2024

@MaxenceGui before_serving was an example, should be applied to the rest of the code too; calls between processes are done to through the protocol linking them (example: HTTP GET/POST), not function calls (which would imply RPC calls).

@MaxenceGui MaxenceGui added this to the M1 (2024Q1) milestone Feb 6, 2024
@CFIALeronB CFIALeronB moved this to In Progress in Nachet Feb 7, 2024
MaxenceGui pushed a commit that referenced this issue Feb 8, 2024
@MaxenceGui MaxenceGui linked a pull request Feb 8, 2024 that will close this issue
13 tasks
MaxenceGui pushed a commit that referenced this issue Feb 12, 2024
MaxenceGui pushed a commit that referenced this issue Feb 12, 2024
@CFIALeronB CFIALeronB moved this from In Progress to Done in Nachet Feb 13, 2024
MaxenceGui pushed a commit that referenced this issue Feb 14, 2024
MaxenceGui pushed a commit that referenced this issue Feb 14, 2024
MaxenceGui pushed a commit that referenced this issue Feb 14, 2024
…d update app.py with new imports and function calls
MaxenceGui pushed a commit that referenced this issue Feb 14, 2024
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
fixes #51: Update sequence diagram

fixes #51: Update doc string

fixes #51: update README and TESTING
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
fixes #51: correcting markdown lint
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
fixes #51: inference test with Quart.test_client

fixes #51: Correct lint ruff error and tests
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
fixes #51: Correct trailing whitespace and EOF.
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
fixes #51 remove literal path
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
fixes #51: Move insert_new_version_pipeline to pipelines_version_insertion.py
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
fixes #51: Refactor model folder
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
fixes #51: fix OEF

Issue #51: Correct typo
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
issue #51: change mermaid theme
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
* # fixes #64: Add MAX_CONTENT_LENGTH env

* fixes #64 Add devSecOps variable name

* fixes #64: fix typo

* Update README.md

Co-authored-by: Jonathan Lopez <[email protected]>

* Update .env.template

Co-authored-by: Jonathan Lopez <[email protected]>

* isssue #64: Get rid of eval

---------

Co-authored-by: Jonathan Lopez <[email protected]>

fixes #51: connecting to swin model

fixes #51: refactor exception

fixes #51: add request_factory function to bring a standard to call model

fixes #51: add models_Utils.py

fixes #51: Update model_utilitary_functions import

fixes #51: update result parsing and add default pipeline

fixes #51: update inference_request to call swin in loop

fixes #51: Standardize headers with azureml-model-deployment being mandantory

fixes #51: correct failed check from workflows

fixes #51: Refactor inference result processing and add test file for inference request

fixes #51: Change the categories model name

fixes #51: implement model module request inference function

fixes #51: add function to retrieve pipeline info from blob storage

fixes #51: Add script to upload to blob storage json file containing pipeline

fixes #51: correct lint error

Update nachet-inference-documentation.md to reflect code change

fixes #51: Update sequence diagram

fixes #51: update README and TESTING

fixes #51: correcting markdown lint

 fixes #51: Add inference request test

fixes #51: inference test with Quart.test_client

fixes #51: Correct lint ruff error and tests

fixes #51: implement Ricky reviews

Update CODEOWNERS file

Update CODEOWNERS file

fixes #64: Increase MAX_CONTENT_LENGTH (#66)

* # fixes #64: Add MAX_CONTENT_LENGTH env

* fixes #64 Add devSecOps variable name

* fixes #64: fix typo

* Update README.md

Co-authored-by: Jonathan Lopez <[email protected]>

* Update .env.template

Co-authored-by: Jonathan Lopez <[email protected]>

* isssue #64: Get rid of eval

---------

Co-authored-by: Jonathan Lopez <[email protected]>
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
issue #51: Give MAX_CONTENT_LENGTH default value

issue #51: Remove legacy folder
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
issue #51: Modify documentation to reflect change on Model namedtuple
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
* Update Sequence Diagram README.md

![SD_1 drawio (2)](https://github.com/ai-cfia/nachet-backend/assets/19809069/272f37dc-f4ec-449b-ba82-950c54b9f856)

issue #51: Fixing Markdown lint

issue #51: fixing MD lint
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
issue #62: correct multiple import ruff error
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
MaxenceGui pushed a commit that referenced this issue Apr 8, 2024
MaxenceGui pushed a commit that referenced this issue Apr 9, 2024
fixes #51: implement pipeline switching in back end
@github-project-automation github-project-automation bot moved this from Waiting on Review to Done in Nachet Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment