Git Product home page Git Product logo

caikit-template's Introduction

Caikit

Build Status Minimum Python Version Release Read the Docs OpenSSF Best Practices

Caikit is an AI toolkit that enables users to manage models through a set of developer friendly APIs. It provides a consistent format for creating and using AI models against a wide variety of data domains and tasks.

Caikit Overview

Capabilities

Caikit streamlines the management of AI models for application usage by letting AI model authors focus on solving well known problems with novel technology. With a set of model implementations based on Caikit, you can:

  • Run training jobs to create models from your data
  • Run model inference using data APIs that represent data as structures rather than tensors
  • Implement the right training techniques to fit the model, from static regexes to multi-GPU distribution
  • Merge models from diverse AI communities into a common API (e.g. transformers, tensorflow, sklearn, etc...)
  • Update applications to newer models for a given task without client-side changes

What Differentiates Caikit from Other AI Model Runtimes?

Developers who write applications that consume AI models are not necessarily AI experts who understand the intricate details of the AI models that they use. Some would like to treat AI as a "black box function" where they give it input and it returns the output. This is similar in cloud computing whereby some users would like to deploy their applications to the cloud without detailed knowledge of the cloud infrastructure. The value for them is in their application and that is what is of most interest to them.

Caikit provides an abstraction layer for application developers where they can consume AI models through APIs independent of understanding the data form of the model. In other words, the input and output to the model is in a format which is easily programmable and does not require data transformations. This facilitates the model and the application to evolve independently of each other.

When deploying a small handful of models, this benefit is minimal. The benefits are generally realized when consuming 10s or hundreds of AI models, or maintaining an application over time as AI technology evolves. Caikit simplifies the scaling and maintenance of such integrations compared to other runtimes. This is because other runtimes require an AI centric view of the model (for example, the common interface of “tensor in, tensor out”) which means having to code different data transformations into the application for each model. Additionally, the data form of the model may change from version to version.

Getting Started

There are 2 key things to define upfront when using Caikit to manage your AI model. They are as follows:

The module defines the entry points for Caikit to manage your model. In other words, it tells Caikit how to load, infer and train your model. An example is the text sentiment module. The data model defines the input and outputs of the model task. An example is the text sentiment data model.

The model is served by a gRPC server which can run as is or in any container runtime, including Knative and KServe. Here is an example of the text sentiment server code for gRPC. This references the module configuration here. This configuration specifies the module(s), which wrap the model(s), to serve.

There is an example of a client here which is a simple Python CLI which calls the model and queries it for sentiment analysis on 2 different pieces of text. The client also references the module configuration.

Check out the full Text Sentiment example to understand how to load and infer a model using Caikit. If you want to get started with developing and integrating your AI model algorithm using Caikit, checkout the GitHub template. In the template repository when you click on the green Use this template button, it generates a repository in your GitHub account with a simple customized module which is wrapped to be served by the Caikit runtime. This template is designed to be extended for module implementations.

User Profiles

There are 2 user profiles who leverage Caikit:

  • AI Model Author:
    • Model Authors build and train AI models for data analysis
    • They bring data and tuning params to a pre-existing model architecture and create a new concrete model using APIs provided by Caikit
    • Examples of model authors are machine learning engineers, data scientists, and AI developers
  • AI Model Operator:
    • Model operators use an existing AI model to perform a specific function within the context of an application
    • They take trained models, deploy them, and then infer the models in applications through APIs provided by Caikit
    • Examples of operators are cloud and embedded application developers whose applications need analysis of unstructured data

Documentation

Get going with Getting Started or jump into more details with the Python API docs.

Contributing

Check out our contributing guide to learn how to contribute to Caikit.

Code of Conduct

Participation in the Caikit community is governed by the Code of Conduct.

caikit-template's People

Contributors

evaline-ju avatar gkumbhat avatar hickeyma avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

caikit-template's Issues

Caikit 0.9.0 breaks extension template

Describe the bug

When I switch my caikit version to 0.9.0, I can no longer run python3 train_model.py successfully as describe in the caikit-template Readme.

Platform

Please provide details about the environment you are using, including the following:

  • Interpreter version: Python 3.11.3
  • Library version: caikit 0.9.0, caikit-template main (up-to-date)

Sample Code

I execute the runtime in one shell:

 cd "${CAIKIT_RAG_PATH}/demo/server/" && python3 start_runtime.py

Inference always works, but when I try to run training as follows, it will hit errors against caikit 0.9.0:

cd "${CAIKIT_RAG_PATH}/demo/client/" && python3 train_model.py

See section below for exact stack traces.

Expected behavior

I expected this sample command to terminate correctly. When I switch caikit to tag 0.8.0, it finishes successfully:

$ cd "${CAIKIT_RAG_PATH}/demo/client/" && python3 train_model.py
<function register_backend_type at 0x7f7167c41bc0> is still in the BETA phase and subject to change!
train data: /home/fpollok/PycharmProjects/caikit-rag/demo/train_data/sample_data.csv
RESPONSE: training_id: "05de3053-5d8c-4bce-94aa-c1bec47af249"
model_name: "hello_world"

Observed behavior

The inference command still works, but when I run training I first hit this error:

$ cd "${CAIKIT_RAG_PATH}/demo/client/" && python3 train_model.py
Cannot generate train rpc for <class 'caikit_template.modules.hello_world.HelloWorldModule'>: module 'caikit.interfaces' has no attribute 'common'
Traceback (most recent call last):
  File "/home/fpollok/PycharmProjects/caikit/caikit/runtime/service_generation/create_service.py", line 95, in create_training_rpcs
    rpcs.append(ModuleClassTrainRPC(signature))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fpollok/PycharmProjects/caikit/caikit/runtime/service_generation/rpcs.py", line 126, in __init__
    self._method = ModuleClassTrainRPC._mutate_method_signature_for_training(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fpollok/PycharmProjects/caikit/caikit/runtime/service_generation/rpcs.py", line 191, in _mutate_method_signature_for_training
    new_params[name] = make_data_stream_source(element_type)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fpollok/PycharmProjects/caikit/caikit/runtime/service_generation/data_stream_source.py", line 255, in make_data_stream_source
    caikit.interfaces.common.data_model,
    ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'caikit.interfaces' has no attribute 'common'
train data: /home/fpollok/PycharmProjects/caikit-rag/demo/train_data/sample_data.csv
Traceback (most recent call last):
  File "/home/fpollok/PycharmProjects/caikit-rag/demo/client/train_model.py", line 49, in <module>
    request = training_service.messages.HelloWorldTaskHelloWorldModuleTrainRequest(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'ClientMessages' has no attribute 'HelloWorldTaskHelloWorldModuleTrainRequest'

i.e., caikit.interfaces.common.data_model cannot be found. So I add from .common import * to caikit/interfaces/__init__.py.

When I try rerunning the script, the AttributeError disappears, but now I hit an InactiveRpcError:

$ cd "${CAIKIT_RAG_PATH}/demo/client/" && python3 train_model.py
train data: /home/fpollok/PycharmProjects/caikit-rag/demo/train_data/sample_data.csv
Traceback (most recent call last):
  File "/home/fpollok/PycharmProjects/caikit-rag/demo/client/train_model.py", line 54, in <module>
    response = client_stub.HelloWorldTaskHelloWorldModuleTrain(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fpollok/.venv/caikit_rag_nlp/lib64/python3.11/site-packages/grpc/_channel.py", line 1030, in __call__
    return _end_unary_response_blocking(state, call, False, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fpollok/.venv/caikit_rag_nlp/lib64/python3.11/site-packages/grpc/_channel.py", line 910, in _end_unary_response_blocking
    raise _InactiveRpcError(state)  # pytype: disable=not-instantiable
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.UNIMPLEMENTED
        details = "Method not found!"
        debug_error_string = "UNKNOWN:Error received from peer  {created_time:"2023-06-22T11:08:03.339314716+02:00", grpc_status:12, grpc_message:"Method not found!"}"
>

Additional context

While I know that caikit-template lists caikit 0.7.0 in its requirements, I want to be able to run my extension against the latest caikit version (or even main).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.