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

[Droid] Add Truss Example for Databricks DBRX-Instruct Model #264

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions databricks-dbrx-instruct/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Databricks DBRX Instruct Truss

This Truss packages the DBRX-Instruct model from Databricks. DBRX-Instruct is an instruction-following language model that can be used for various language tasks.

## Deploying

To deploy this model using Truss, follow these steps:

1. Clone this repo
2. Set up a Baseten account and install the Truss CLI
3. Run `truss deploy` to deploy the model on Baseten

## Model Overview

// TODO: Add a brief overview of the DBRX-Instruct model and its key capabilities

## API Documentation

// TODO: Document the key API endpoints, request parameters, and response format

## Example Usage

// TODO: Provide example code snippets demonstrating how to use the deployed model via its API
1 change: 1 addition & 0 deletions databricks-dbrx-instruct/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty file
1 change: 1 addition & 0 deletions databricks-dbrx-instruct/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty file
41 changes: 41 additions & 0 deletions databricks-dbrx-instruct/model/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import logging

from transformers import AutoModelForCausalLM, AutoTokenizer

logger = logging.getLogger(__name__)


class Model:
def __init__(self, model_name="databricks/dbrx-instruct") -> None:
self.model_name = model_name
self.model = None
self.tokenizer = None

def load(self):
try:
self.tokenizer = AutoTokenizer.from_pretrained(self.model_name)
self.model = AutoModelForCausalLM.from_pretrained(self.model_name)
except Exception as e:
logger.error(f"Failed to load model {self.model_name}: {e}")
raise

def preprocess(self, request: dict) -> dict:
prompt = request.get("prompt", "")
return {"input_ids": self.tokenizer.encode(prompt, return_tensors="pt")}

def postprocess(self, output) -> dict:
return {
"generated_text": self.tokenizer.decode(output[0], skip_special_tokens=True)
}

def predict(self, request: dict) -> dict:
try:
processed_input = self.preprocess(request)
output = self.model.generate(**processed_input)
return self.postprocess(output)
except Exception as e:
logger.error(f"Prediction failed: {e}")
raise


# Empty file
Loading