Skip to content

Commit

Permalink
Added example and added to mkdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
milo157 committed Jun 12, 2024
1 parent ee13633 commit d217931
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/cerebrium/cerebrium.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[cerebrium.deployment]
name = "cerebrium"
python_version = "3.11"
cuda_version = "12"
include = "[./*, main.py, cerebrium.toml]"
exclude = "[.*]"
shell_commands = []

[cerebrium.hardware]
cpu = 2
memory = 14.0
gpu = "AMPERE A10"
gpu_count = 1
provider = "aws"
region = "us-east-1"

[cerebrium.scaling]
min_replicas = 0
max_replicas = 5
cooldown = 60

[cerebrium.dependencies.pip]
outline = "==0.0.37"
transformers = "==4.38.2"
datasets = "==2.18.0"
accelerate = "==0.27.2"

52 changes: 52 additions & 0 deletions examples/cerebrium/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import outlines

model = outlines.models.transformers("mistralai/Mistral-7B-Instruct-v0.2")
generator = outlines.generate.json(model, schema)

schema = {
"title": "Character",
"type": "object",
"properties": {
"name": {
"title": "Name",
"maxLength": 10,
"type": "string"
},
"age": {
"title": "Age",
"type": "integer"
},
"armor": {"$ref": "#/definitions/Armor"},
"weapon": {"$ref": "#/definitions/Weapon"},
"strength": {
"title": "Strength",
"type": "integer"
}
},
"required": ["name", "age", "armor", "weapon", "strength"],
"definitions": {
"Armor": {
"title": "Armor",
"description": "An enumeration.",
"enum": ["leather", "chainmail", "plate"],
"type": "string"
},
"Weapon": {
"title": "Weapon",
"description": "An enumeration.",
"enum": ["sword", "axe", "mace", "spear", "bow", "crossbow"],
"type": "string"
}
}
}

def generate(
prompt: str = "Amiri, a 53 year old warrior woman with a sword and leather armor.",
):

character = generator(
f"<s>[INST]Give me a character description. Describe {prompt}.[/INST]"
)

print(character)
return character
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ nav:
- Playing chess: cookbook/models_playing_chess.md
- Run on the cloud:
- BentoML: cookbook/deploy-using-bentoml.md
- Cerebrium: cookbook/deploy-using-cerebrium.md
- Modal: cookbook/deploy-using-modal.md
- Docs:
- reference/index.md
Expand Down

0 comments on commit d217931

Please sign in to comment.