Coder Social home page Coder Social logo

ai-wasm's Introduction

A simple example of exporting a transformer model with Python, then loading it into tract to do question answering via Extractive QA. This example uses the MobileBERT model (previous commits contain an Albert model implementation). We also load it into Redpanda (via WebAssembly!) to show how AI models can be embedded directly into your favorite message broker.

To Use

First export the pre-trained transformer model using Python and PyTorch.

pip3 install transformers torch torchinfo
python3 export.py

the exported model and tokenizer are saved in ./mobilebert. Then build the wasm module for deployment in Redpanda.

RUSTFLAGS="-Ctarget-feature=+simd128" cargo build --release --target=wasm32-wasi

Enable WebAssembly and tweak configs in the latest build of Redpanda:

rpk cluster config set data_transforms_enabled true
# NOTE: These limits allow for a single transform with half a GiB of memory.
rpk cluster config set data_transforms_per_core_memory_reservation 536870912
rpk cluster config set data_transforms_per_function_memory_limit 536870912
# Since we're hackily embedding the model in the Wasm binary, we need to support large binaries.
rpk cluster config set data_transforms_binary_max_size 125829120
# Allow some extra time on startup over the default. This could probably be lower.
rpk cluster config set data_transforms_runtime_limit_ms 30000
# Restart Redpanda!

Deploy the model into Redpanda!

rpk topic create questions answers -r 3
rpk wasm deploy --file ./target/wasm32-wasi/release/ai-qa-wasi.wasm \
  --input-topic questions \
  --output-topic answers \
  --var CONTENT='My name is Bert and I live in the broker.'

echo "What is my name?" | rpk topic produce questions
rpk topic consume answers

ai-wasm's People

Contributors

rockwotj avatar

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.