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

Migrate https://github.com/cohere-ai/cohere-aws #364

Open
wants to merge 204 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
204 commits
Select commit Hold shift + click to select a range
8dbbd06
Initial commit
daulet Nov 22, 2022
9e70976
Update README.md
daulet Nov 22, 2022
c992a6e
aws notebook
jpekmez Nov 22, 2022
363221d
add initial python SDK
Nov 22, 2022
fabf095
add SDK tests
Nov 22, 2022
c621eb0
add more tests
Nov 22, 2022
9555120
add simple README
Nov 22, 2022
8176899
verify pip install works
Nov 23, 2022
c0437f4
update aws notebook with cohere-sagemaker
jpekmez Nov 23, 2022
5f5cf0e
update SDK to only expose params that are supported in v1 release
Nov 23, 2022
be06b8f
Merge pull request #1 from cohere-ai/notebook-v0
co-sudip Nov 23, 2022
91ddf07
release v0.2 of the package
Nov 23, 2022
8561187
Update getting started notebook with improved examples (#2)
CoderHam Nov 23, 2022
efcd983
Remove return_likelihoods parameter (#3)
daulet Nov 24, 2022
4690294
Add additional examples demonstrating use cases for co.generate (#4)
co-sudip Nov 24, 2022
df8377b
Updating notebook to include a model package map. (#5)
co-sudip Nov 26, 2022
358c51b
feat: stop_sequences, tuncate, likelihoods (#6)
jpekmez Dec 20, 2022
d2d494a
Support embed in python sdk (#7)
nliu96 Jan 25, 2023
cc9a2d9
add documentation how to upload package (#10)
daulet Jan 27, 2023
8a5ee64
docs: remove trailing white space (#11)
jpekmez Jan 31, 2023
a8b646c
adding sample input/output and updating the notebook with listing inf…
co-sudip Feb 14, 2023
71c7463
Better notebook examples for updated model (#13)
nliu96 Feb 18, 2023
a98d49e
Add rerank (#14)
1vn Mar 14, 2023
0e66b4c
Rerank notebook (#15)
1vn Mar 14, 2023
e96ba1e
add rerank input/outputs (#16)
1vn Mar 14, 2023
7b1d157
Update ARNs of medium model. (#17)
co-sudip Apr 4, 2023
d9d4422
docs: command XL notebook (#18)
jpekmez Apr 7, 2023
3cf8ad2
Finetune classification refactor (#20)
alex-matton May 3, 2023
3d39bd8
add rerank multilingual notebook/samples with temp values (#23)
lfayoux May 8, 2023
261aff8
add new param to rerank endpoint (#22)
lfayoux May 8, 2023
2745124
fix exception handling and update version (#24)
alex-matton May 8, 2023
25cd29d
fix incompatibility issues (#25)
alex-matton May 9, 2023
6235ff3
Improve role handling (#26)
alex-matton May 9, 2023
5c0e6b8
bump version to 0.6.2 (#27)
alex-matton May 9, 2023
4b3568a
update rerank notebooks and sample input/output (#28)
lfayoux May 10, 2023
a66fd1b
update rerank notebooks with supported regions (#29)
lfayoux May 11, 2023
be91967
refactor: remove pres_penalty and freq_penalty (#19)
jpekmez May 17, 2023
8371353
Untar finetunes before aggregation to new tarfile (#30)
alex-matton May 30, 2023
4b6da14
docs: update / multilingual ARN (#32)
jpekmez Jun 7, 2023
3d1b1c1
Add arn to classification notebook (#33)
alex-matton Jun 9, 2023
4968aa0
replace TODO in classification notebook with proper link (#34)
alex-matton Jun 9, 2023
1a6141b
docs: update model package map for command (#36)
jpekmez Jun 23, 2023
4154a87
Summarize endpoint (#38)
leilacc Jul 12, 2023
38717b9
Summarize Notebook (#37)
leilacc Jul 13, 2023
e5a7321
Update DEVELOPMENT.md (#39)
leilacc Jul 13, 2023
ed47f32
use same default temp as dory (#42)
leilacc Jul 13, 2023
2279c7d
summarize samples (#41)
leilacc Jul 13, 2023
0189d79
increment version (#44)
leilacc Jul 13, 2023
749b848
Use multipart copy to avoid size limit of 5GB (#40)
CoderHam Jul 13, 2023
7b815d0
docs: upgrade cohere-sagemaker (#46)
jpekmez Jul 17, 2023
e951190
Update summarize package listing and name (#45)
leilacc Jul 17, 2023
498800b
Add remaining regions to notebooks that only listed limited regions (…
leilacc Jul 17, 2023
13e16a1
Add support for finetune hyperparams (#35)
CoderHam Jul 24, 2023
9d8d282
Fix minor typo in algorithm arns for gen finetunes (#48)
CoderHam Jul 24, 2023
b9c1687
Update Deploy command medium.ipynb (#50)
andrewvonrosenbach Aug 9, 2023
c358afb
Update model package to v1.1.0 (#51)
andrewvonrosenbach Aug 9, 2023
2b37c4e
Update Deploy command XL.ipynb (#52)
andrewvonrosenbach Aug 9, 2023
e68feb1
Update Deploy command medium.ipynb (#53)
andrewvonrosenbach Aug 9, 2023
875fb7d
Classification finetuning v2 (#55)
alex-matton Aug 23, 2023
1acc9b2
Add model as parameter for generate (#57)
CoderHam Sep 12, 2023
bf494ce
Update classification notebooks (#58)
alex-matton Sep 13, 2023
24c03f5
fix english classification notebook (#60)
alex-matton Sep 13, 2023
666974c
num_generations (#61)
leilacc Sep 19, 2023
dd5552d
Update notebook for vanilla, train epochs and stacked t-few (#62)
CoderHam Sep 20, 2023
48d4f3d
Create CODEOWNERS (#64)
daulet Sep 25, 2023
fa32411
Update Deploy multilingual model.ipynb (#56)
jkedrzyckii Sep 26, 2023
eefda69
Fix tests (#63)
leilacc Sep 26, 2023
54a97b0
Support streaming (#65)
leilacc Sep 27, 2023
aa0ef9b
Move commits from cohere-aws back onto cohere-sagemaker (#67)
leilacc Sep 27, 2023
d6d2b1e
s/cohere_sagemaker/cohere_aws (#68)
leilacc Sep 27, 2023
cc405d4
Bedrock notebook (#69)
leilacc Sep 28, 2023
d09df75
bump default max_tokens to 400 to match bedrock playground (#70)
leilacc Sep 28, 2023
1ee2b36
use new bedrock service name (#71)
leilacc Sep 28, 2023
4ee9bed
Fix Bedrock notebook & add streaming example (#72)
leilacc Sep 29, 2023
501f13e
docs: batch Transform not supported (#31)
jpekmez Oct 6, 2023
5e25bda
fix: move notebooks and samples (#73)
jpekmez Oct 19, 2023
6a878fc
Update Deploy command XL.ipynb (#74)
jkedrzyckii Nov 1, 2023
f1b258c
only use timeouts for non-finetune model deploys (#75)
lfayoux Nov 1, 2023
25b13d7
split embed to sagemaker/bedrock, add input_type field (#77)
lfayoux Nov 8, 2023
3d959ef
[embed] embed v3 api and demo notebook update (#76)
alekhya-n Nov 9, 2023
0a4e843
[embed] embed v3 samples for each model (#78)
alekhya-n Nov 9, 2023
b89f439
update sample output (#79)
alekhya-n Nov 9, 2023
9becb62
[embed] update demo notebook with arns (#80)
alekhya-n Nov 10, 2023
2db6918
Add links to all four embed listings (#81)
andrewvonrosenbach Nov 10, 2023
23f96c3
minor formatting fix (#82)
andrewvonrosenbach Nov 10, 2023
b5de232
dont require connected endpoint for bedrock (#84)
lfayoux Nov 13, 2023
5f022c4
call invoke_model instead of invoke_endpoint for bedrock embed (#85)
lfayoux Nov 13, 2023
ee14d3d
Embed v3 bedrock notebook (#86)
leilacc Nov 13, 2023
f89a3ed
fix: Command model notebooks (#87)
leilacc Nov 14, 2023
33b06a8
Financial multilingual embed notebook (#88)
gonzalocohere Nov 21, 2023
be88ee4
Bedrock fintuning (#89)
lfayoux Nov 29, 2023
c9064a8
Updated model package to v1.1.5 (#90)
andrewvonrosenbach Nov 30, 2023
0530f64
add notebook for finetuning bedrock command (#91)
lfayoux Dec 4, 2023
abb63c4
Update listing URLs and model package to v1.0.0 (#93)
andrewvonrosenbach Dec 7, 2023
6a27d2e
Updating model package to 2.0.1 version (#83)
andrewvonrosenbach Dec 7, 2023
08c5252
Add language indicating Batch Transform is not supported for Classifi…
andrewvonrosenbach Dec 8, 2023
789f375
Update Deploy rerank english model.ipynb (#95)
jkedrzyckii Dec 9, 2023
7a77a9f
finetune notebooks (#96)
innainu Dec 11, 2023
8b63219
move sagemaker related notebooks to sagemaker dir (#101)
innainu Dec 11, 2023
09aaab1
Rename Deploy command XL.ipynb to Deploy command.ipynb (#99)
jkedrzyckii Dec 11, 2023
9267581
Rename Deploy command medium.ipynb to Deploy command-light.ipynb (#100)
jkedrzyckii Dec 11, 2023
ddc774e
Update and rename Deploy command medium.ipynb to Deploy command light…
jkedrzyckii Dec 11, 2023
7edeeb4
Update and rename Deploy command XL.ipynb to Deploy command.ipynb (#103)
jkedrzyckii Dec 11, 2023
fe75174
cleanup duplicate notebooks (#104)
innainu Dec 11, 2023
939d60e
Financial multilingual embed notebook (#105)
gonzalocohere Dec 14, 2023
b0acc76
Update Deploy command light.ipynb (#107)
jkedrzyckii Feb 1, 2024
799263b
Update Deploy command.ipynb (#106)
jkedrzyckii Feb 1, 2024
88fd93a
Update Deploy embed v3 model.ipynb (#108)
jkedrzyckii Mar 4, 2024
d89e9fc
Add chat to cohere-aws sdk, add command-r notebook (#109)
lfayoux Apr 4, 2024
2681e39
Add command-r samples that weren't merged previously (#114)
andrewvonrosenbach Apr 5, 2024
e23c77b
update command-r listing links in notebooks; add 1 model_pkg per inst…
lfayoux Apr 5, 2024
79aced5
bump version to 0.8.12 (#113)
lfayoux Apr 5, 2024
64588c5
fix cmd-r notebook generate -> chat (#116)
lfayoux Apr 10, 2024
3c0caaf
added new examples for rerank (#111)
mahjongmen Apr 10, 2024
000c2b2
Update Deploy rerank english v3.0 model.ipynb (#117)
jkedrzyckii Apr 11, 2024
693dccb
Update Deploy rerank multilingual v3.0 model.ipynb (#118)
jkedrzyckii Apr 11, 2024
2488292
Update rerank_multilingual_v3_input.json (#120)
mahjongmen Apr 11, 2024
2235c94
fix cmd-r notebook example (#121)
lfayoux Apr 11, 2024
0532959
Update Deploy rerank english v3.0 model.ipynb (#123)
jkedrzyckii Apr 15, 2024
bcbb7f4
Update Deploy rerank multilingual v3.0 model.ipynb (#122)
jkedrzyckii Apr 19, 2024
2b2d28f
Update Deploy rerank english v2.0 model.ipynb (#127)
jkedrzyckii Apr 19, 2024
68728a4
Update Deploy rerank multilingual v2.0 model.ipynb (#128)
jkedrzyckii Apr 19, 2024
c898cd7
Update Deploy rerank english v3.0 model.ipynb (#125)
jkedrzyckii Apr 19, 2024
4dce88b
Update Deploy rerank multilingual v3.0 model.ipynb (#126)
jkedrzyckii Apr 19, 2024
5f1f515
add notebooks for cmd-r and cmd-r+; unblock chat bedrock from the sdk…
lfayoux Apr 22, 2024
273e5e2
update marketplace links (#129)
lfayoux Apr 22, 2024
3859e23
remove stream param from request before sending (#134)
lfayoux Apr 30, 2024
1f7425e
feat: Command-R finetuning (#132)
mike-meow May 8, 2024
5f79498
Update Run command R finetuning.ipynb (#135)
jkedrzyckii May 9, 2024
d9dff2e
Fix typo (#136)
joon0711 May 9, 2024
01a489f
feat: uncomment sagemaker notebook map (#137)
mike-meow May 9, 2024
b86b8d6
fix: fix command R marketplace link (#138)
mike-meow May 22, 2024
b1c2226
Update Deploy command-r.ipynb (#139)
jkedrzyckii May 24, 2024
dc242d9
Update Deploy command-r-plus.ipynb (#140)
jkedrzyckii May 24, 2024
e51f191
fix bedrock non stream chat (#142)
lfayoux Jun 4, 2024
1d66761
Add redirect to the platform sdks (#143)
billytrend-cohere Jun 17, 2024
50b9524
Update Deploy command-r.ipynb (#144)
jkedrzyckii Jun 27, 2024
e828baa
Update Deploy command-r-plus.ipynb (#145)
jkedrzyckii Jun 27, 2024
7e2bbca
Update Deploy embed v3 model.ipynb (#148)
jkedrzyckii Jun 27, 2024
b5bc658
Update Deploy rerank english v3.0 model.ipynb (#146)
jkedrzyckii Jun 27, 2024
6482319
Update Deploy rerank multilingual v3.0 model.ipynb (#147)
jkedrzyckii Jun 27, 2024
1b9d982
rerank nimble notebooks (#149)
alekhya-n Jul 15, 2024
d170f2e
Update Deploy rerank nimble english v3.0 model.ipynb (#150)
jkedrzyckii Jul 16, 2024
4e9668c
Update Deploy rerank nimble multilingual v3.0 model.ipynb (#151)
jkedrzyckii Jul 16, 2024
6346cbd
Update Deploy rerank multilingual v3.0 model.ipynb (#153)
pradeep-prabhakaran Aug 8, 2024
18d4b7c
Update Deploy rerank english v3.0 model.ipynb (#156)
pradeep-prabhakaran Aug 8, 2024
380a91b
Update Deploy rerank multilingual v3.0 model.ipynb (#155)
pradeep-prabhakaran Aug 8, 2024
fe924ce
docs: add readme to sagemaker dir (#157)
GangGreenTemperTatum Aug 15, 2024
8f6c76d
Add notebooks for R/R+ 0824 (#158)
CoderHam Aug 30, 2024
b86243d
Update Deploy command-r-plus-0824.ipynb (#159)
jkedrzyckii Aug 30, 2024
5b37455
Update Deploy command-r-0824.ipynb (#160)
jkedrzyckii Aug 30, 2024
a8f5de8
Update Deploy command-r.ipynb (#161)
jkedrzyckii Aug 30, 2024
58a560e
Update Deploy command-r-plus.ipynb (#162)
jkedrzyckii Aug 30, 2024
ee09832
Update Deploy rerank english v3.0 model.ipynb (#163)
jkedrzyckii Sep 4, 2024
5cc81ed
Update Deploy rerank multilingual v3.0 model.ipynb (#164)
jkedrzyckii Sep 4, 2024
8b6e072
Update Deploy rerank nimble english v3.0 model.ipynb (#165)
jkedrzyckii Sep 4, 2024
3ec06fd
Update Deploy rerank nimble multilingual v3.0 model.ipynb (#166)
jkedrzyckii Sep 4, 2024
92f646c
Support SageMaker BYO finetuning (#168)
youran-qi Sep 26, 2024
05b5f67
feat: juypter notebook for command r 0824 finetuning (#169)
mike-meow Sep 26, 2024
8b9d5cc
Modify BYO Notebook (#170)
youran-qi Sep 27, 2024
64ecd06
feat: update command R finetune notebook for cohere-python-sdk 0.5.11…
mike-meow Sep 30, 2024
bec2d82
Update Deploy rerank multilingual v3.0 model.ipynb (#173)
jkedrzyckii Oct 1, 2024
fcaedaa
Update Deploy rerank english v3.0 model.ipynb (#174)
jkedrzyckii Oct 1, 2024
c6a7c1c
Update Deploy rerank nimble multilingual v3.0 model.ipynb (#175)
jkedrzyckii Oct 1, 2024
1ea87ff
Update Deploy rerank nimble english v3.0 model.ipynb (#176)
jkedrzyckii Oct 1, 2024
9ad9290
Update Deploy embed v3 model.ipynb (#177)
jkedrzyckii Oct 1, 2024
2592857
Update Deploy command-r-plus.ipynb (#180)
jkedrzyckii Oct 1, 2024
f46109e
Update Deploy command-r.ipynb (#181)
jkedrzyckii Oct 1, 2024
f6fdeb2
Update Deploy command-r-0824.ipynb (#178)
jkedrzyckii Oct 1, 2024
c092a11
Update Deploy command-r-plus-0824.ipynb (#179)
jkedrzyckii Oct 1, 2024
e73b0b5
docs: update for arns and urls for r v2 finetuning + misc fixes (#182)
CoderHam Oct 2, 2024
f8769f0
Change cohere-aws to cohere in the BYO notebook (#172)
youran-qi Oct 2, 2024
64075e9
Update Deploy embed v3 model.ipynb (#183)
jkedrzyckii Oct 22, 2024
84a5528
Update Deploy rerank multilingual v3.0 model.ipynb (#184)
ryanchase-cohere Oct 30, 2024
4f505f6
Update link to AWS Marketplace to point to Rerank V3 (#185)
ryanchase-cohere Oct 30, 2024
945da3f
Update Deploy rerank english v3.0 model.ipynb (#188)
gloriacohere Nov 15, 2024
8bc0ffc
Update Deploy embed v3 model.ipynb (#189)
gloriacohere Nov 15, 2024
b87df0e
Update Deploy command-r-0824.ipynb (#191)
gloriacohere Nov 18, 2024
4666288
Update Deploy command-r-plus-0824.ipynb (#190)
gloriacohere Nov 18, 2024
21f4e0c
fix: unreadable notebooks (#197)
jpekmez Nov 20, 2024
fcca2f5
fix: use setuptools==69.5.1 (#198)
jpekmez Nov 21, 2024
9679f3d
create endpoint with InferenceAmiVersion (#196)
jpekmez Nov 22, 2024
1859f5b
chore: package v0.8.17 (#199)
jpekmez Nov 22, 2024
712c5f7
Create rerank_v3.5_output.json (#201)
jkedrzyckii Nov 29, 2024
407fa56
Create rerank_v3.5_input.json (#200)
jkedrzyckii Nov 29, 2024
dd9ce5b
Update rerank_v3.5_input.json (#204)
jkedrzyckii Nov 29, 2024
6735a1e
Update Deploy embed v3 model.ipynb (#203)
jkedrzyckii Nov 29, 2024
3a307ec
adjusted the hyperlinks in rerank notebooks (#205)
mahjongmen Dec 1, 2024
f8a4ebe
Update rerank_v3.5_input.json (#206)
mkozakov Dec 1, 2024
b0c38a3
added rerank-3.5 notebook (#207)
mahjongmen Dec 1, 2024
c65325c
Update Deploy rerank-v3.5.ipynb (#208)
jkedrzyckii Dec 2, 2024
58194d8
Update Deploy rerank-v3.5.ipynb (#209)
gloriacohere Dec 3, 2024
2a663d8
Use cohere-python sdk (#210)
billytrend-cohere Dec 4, 2024
68a94d6
Update Deploy rerank english v3.0 model.ipynb (#211)
jkedrzyckii Dec 16, 2024
dd434d1
Update Deploy rerank multilingual v3.0 model.ipynb (#212)
jkedrzyckii Dec 16, 2024
47df09c
Update Deploy rerank nimble english v3.0 model.ipynb (#213)
jkedrzyckii Dec 16, 2024
b1a7cb9
Update Deploy rerank-v3.5.ipynb (#214)
jkedrzyckii Dec 16, 2024
81cfc2f
Update Deploy command-r-plus.ipynb (#217)
jkedrzyckii Dec 16, 2024
8e07752
Update Deploy embed v3 model.ipynb (#215)
jkedrzyckii Dec 16, 2024
babef10
Update Deploy command-r.ipynb (#216)
jkedrzyckii Dec 16, 2024
453b486
Update Deploy command-r-plus-0824.ipynb (#219)
jkedrzyckii Dec 16, 2024
a28a909
Update Deploy command-r-0824.ipynb (#218)
jkedrzyckii Dec 16, 2024
b2daf2d
update botocore version (#220)
alekhya-n Dec 20, 2024
24de87f
Merge remote-tracking branch 'aws/main' into HEAD
billytrend-cohere Jan 16, 2025
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
423 changes: 423 additions & 0 deletions notebooks/bedrock/Financial Multilingual Embeddings.ipynb

Large diffs are not rendered by default.

296 changes: 296 additions & 0 deletions notebooks/bedrock/Finetune command light model.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Finetune and deploy Cohere Command Light Model from AWS Bedrock\n",
"\n",
"This sample notebook shows you how to finetune and deploy cohere command light models using Amazon SageMaker.\n",
"\n",
"> **Note**: This is a reference notebook and it cannot run unless you make changes suggested in the notebook.\n",
"\n",
"## Pre-requisites:\n",
"1. **Note**: This notebook contains elements which render correctly in Jupyter interface. Open this notebook from an Amazon SageMaker Notebook Instance or Amazon SageMaker Studio.\n",
"1. Ensure that you have an IAM role set up for bedrock model customization https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-iam-role.html\n",
"\n",
"## Contents:\n",
"1. [Subscribe to Amazon Bedrock](#1.-Subscribe-to-Amazon-Bedrock)\n",
"2. [Run the model customization job](#2.-Run-the-model-customization-job)\n",
" 1. [Upload training data](#A.-Upload-training-data)\n",
" 2. [Finetune models on uploaded data](#B.-Finetune-models-on-uploaded-data)\n",
" 3. [Wait for job to complete](#C.-Wait-for-job-to-complete)\n",
"3. [Create an endpoint for inference](#3.-Create-an-endpoint-for-inference)\n",
" 1. [Provision model throughput](#A.-Provision-model-throughput)\n",
" 2. [Perform real-time inference](#B.-Perform-real-time-inference)\n",
"4. [Clean-up](#4.-Clean-up)\n",
" 1. [Delete the endpoint](#A.-Delete-the-endpoint) \n",
"\n",
"## Usage instructions\n",
"You can run this notebook one cell at a time (By using Shift+Enter for running a cell)."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Subscribe to Amazon Bedrock"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Follow the instructions in the [Amazon Bedrock](https://console.aws.amazon.com/bedrock) console and [add access](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html) to the cohere command light model."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Run the model customization job"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install --upgrade setuptools==69.5.1 cohere-aws\n",
"# if you upgrade the package, you need to restart the kernel\n",
"\n",
"import cohere_aws\n",
"import boto3"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### A. Upload training data\n",
"\n",
"Choose a directory on S3 to store the training data:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s3_bucket_name = \"finetune-data\" # bucket where data should be uploaded to, your bedrock model customization IAM role should also have access to this bucket\n",
"s3_train_data_path = \"generative/train.jsonl\" # the path where train data will be stored\n",
"s3_eval_data_path = \"generative/eval.jsonl\" # the path where eval data will be stored (optional)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Upload sample training data and optional eval data to S3:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s3 = boto3.client('s3')\n",
"\n",
"# upload example data to s3\n",
"s3.upload_file(\"../examples/sample_generative_data.jsonl\", s3_bucket_name, s3_train_data_path)\n",
"s3.upload_file(\"../examples/sample_generative_data_eval.jsonl\", s3_bucket_name, s3_eval_data_path) # (optional)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### B. Finetune models on uploaded data\n",
"\n",
"Specify a directory on S3 where finetuned models should be stored:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s3_models_dir = \"s3://finetuned_models/\" # where the models will be saved"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Create Cohere client:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"region = boto3.Session().region_name\n",
"co = cohere_aws.Client(mode=cohere_aws.Mode.BEDROCK, region_name=region)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Create the fine-tuning job:\n",
"> **Note**: Update the role ARN with the role created in step 2 of the pre-requisites"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"train_data_url = f\"s3://{s3_bucket_name}/{s3_train_data_path}\"\n",
"eval_data_url = f\"s3://{s3_bucket_name}/{s3_eval_data_path}\"\n",
"\n",
"job_id = co.create_finetune(\n",
" name=\"finetuned-model\",\n",
" base_model_id=\"cohere.command-light-text-v14:7:4k\", \n",
" train_data=train_data_url,\n",
" s3_models_dir=s3_models_dir,\n",
" eval_data=eval_data_url, \n",
" role=\"arn:aws:iam::<ACCOUNT_ID>:role/service-role/<ROLE_NAME>\"\n",
")\n",
"print(job_id)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### C. Wait for job to complete\n",
"\n",
"> **Note**: This job may take a while to complete, if it does not complete within the timeout your job will still be running and you may need to wait longer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model_id = co.wait_for_finetune_job(job_id)\n",
"print(model_id)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Create an endpoint for inference"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### A. Provision model throughput\n",
"\n",
"The Cohere AWS SDK provides a built-in method for provisioning throughput to inference finetuned models.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model_arn = co.provision_throughput(model_id=model_id, name=\"custom-model-throughput\", model_units=1)\n",
"print(model_arn)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### B. Perform real-time inference\n",
"\n",
"Now, you can access all models deployed on the endpoint for inference:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"result = co.generate(prompt=\"hello\", model_id=model_arn)\n",
"print(result)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Clean-up"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### A. Delete the endpoint\n",
"\n",
"After you've successfully performed inference, you can delete the deployed endpoint to avoid being charged continuously."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bedrock = boto3.client(\"bedrock\", region_name=region)\n",
"bedrock.delete_provisioned_model_throughput(model_arn)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "emb",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading
Loading