Skip to content

Commit ef4ee1d

Browse files
authored
Merge branch 'main' into fix/wait-flag
2 parents 0f341bf + 1201470 commit ef4ee1d

58 files changed

Lines changed: 9500 additions & 1522 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/devcontainers/python:3.9
1+
FROM mcr.microsoft.com/devcontainers/python:3.10
22

33
ENV PYTHONUNBUFFERED 1
44

.github/workflows/_integration_tests.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,27 @@ name: integration-tests
33
on:
44
push:
55
branches: [ main ]
6-
paths:
7-
- "**.py"
6+
paths-ignore:
7+
- "**.md"
88

99
pull_request:
1010
branches: [ main ]
11-
paths:
12-
- "**.py"
11+
paths-ignore:
12+
- "**.md"
1313

1414
concurrency:
1515
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
1616
cancel-in-progress: true
1717

1818
env:
19-
POETRY_VERSION: "1.7.1"
19+
POETRY_VERSION: "2.1.1"
2020

2121
jobs:
2222
build:
2323
runs-on: ubuntu-latest
2424
strategy:
2525
matrix:
2626
python-version:
27-
- "3.9"
2827
- "3.10"
2928
- "3.11"
3029
- "3.12"
@@ -39,14 +38,10 @@ jobs:
3938
poetry-version: ${{ env.POETRY_VERSION }}
4039
cache-key: core
4140

42-
- name: Install dependencies
41+
- name: Install together with dependencies
4342
shell: bash
4443
run: poetry install --with quality,tests
4544

46-
- name: Install together
47-
run: |
48-
poetry run pip install .
49-
5045
- name: Run integration tests
5146
shell: bash
5247
env:

.github/workflows/_tests.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ name: unit-tests
33
on:
44
push:
55
branches: [ main ]
6-
paths:
7-
- "**.py"
6+
paths-ignore:
7+
- "**.md"
88

99
pull_request:
1010
branches: [ main ]
11-
paths:
12-
- "**.py"
11+
paths-ignore:
12+
- "**.md"
1313

1414
concurrency:
1515
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -24,7 +24,6 @@ jobs:
2424
strategy:
2525
matrix:
2626
python-version:
27-
- "3.9"
2827
- "3.10"
2928
- "3.11"
3029
- "3.12"

.github/workflows/check_code_quality.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ name: pre-commit
33
on:
44
push:
55
branches: [ main ]
6-
paths:
7-
- "**.py"
86

97
pull_request:
108
branches: [ main ]
11-
paths:
12-
- "**.py"
139

1410
concurrency:
1511
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}

.github/workflows/upload-to-pypi.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
release:
55
types: [published]
66

7+
env:
8+
POETRY_VERSION: "2.1.1"
9+
710
jobs:
811
build:
912
runs-on: ubuntu-latest
@@ -13,13 +16,12 @@ jobs:
1316

1417
steps:
1518
- uses: actions/checkout@v4
16-
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v5
19+
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
20+
uses: "./.github/actions/poetry_setup"
1821
with:
1922
python-version: ${{ matrix.python-version }}
20-
21-
- name: Install poetry
22-
run: curl -sSL https://install.python-poetry.org | python3 -
23+
poetry-version: ${{ env.POETRY_VERSION }}
24+
cache-key: core
2325

2426
- name: Set up cache
2527
uses: actions/cache@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,4 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
test_data/

README.md

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
# Together Python API library
88

99
[![PyPI version](https://img.shields.io/pypi/v/together.svg)](https://pypi.org/project/together/)
10-
[![Discord](https://dcbadge.vercel.app/api/server/9Rk6sSeWEG?style=flat&compact=true)](https://discord.com/invite/9Rk6sSeWEG)
10+
[![Discord](https://dcbadge.limes.pink/api/server/https://discord.gg/9Rk6sSeWEG?style=flat&theme=discord-inverted)](https://discord.com/invite/9Rk6sSeWEG)
1111
[![Twitter](https://img.shields.io/twitter/url/https/twitter.com/togethercompute.svg?style=social&label=Follow%20%40togethercompute)](https://twitter.com/togethercompute)
1212

13-
The [Together Python API Library](https://pypi.org/project/together/) is the official Python client for Together's API platform, providing a convenient way for interacting with the REST APIs and enables easy integrations with Python 3.8+ applications with easy to use synchronous and asynchronous clients.
13+
The [Together Python API Library](https://pypi.org/project/together/) is the official Python client for Together's API platform, providing a convenient way for interacting with the REST APIs and enables easy integrations with Python 3.10+ applications with easy to use synchronous and asynchronous clients.
1414

1515

1616

@@ -58,7 +58,7 @@ client = Together()
5858

5959
# Simple text message
6060
response = client.chat.completions.create(
61-
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
61+
model="meta-llama/Llama-4-Scout-17B-16E-Instruct",
6262
messages=[{"role": "user", "content": "tell me about new york"}],
6363
)
6464
print(response.choices[0].message.content)
@@ -148,7 +148,7 @@ from together import Together
148148

149149
client = Together()
150150
stream = client.chat.completions.create(
151-
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
151+
model="meta-llama/Llama-4-Scout-17B-16E-Instruct",
152152
messages=[{"role": "user", "content": "tell me about new york"}],
153153
stream=True,
154154
)
@@ -173,7 +173,7 @@ async def async_chat_completion(messages):
173173
async_client = AsyncTogether()
174174
tasks = [
175175
async_client.chat.completions.create(
176-
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
176+
model="meta-llama/Llama-4-Scout-17B-16E-Instruct",
177177
messages=[{"role": "user", "content": message}],
178178
)
179179
for message in messages
@@ -186,6 +186,30 @@ async def async_chat_completion(messages):
186186
asyncio.run(async_chat_completion(messages))
187187
```
188188

189+
#### Fetching logprobs
190+
191+
Logprobs are logarithms of token-level generation probabilities that indicate the likelihood of the generated token based on the previous tokens in the context. Logprobs allow us to estimate the model's confidence in its outputs, which can be used to decide how to optimally consume the model's output (e.g. rejecting low confidence outputs, retrying or ensembling model outputs etc).
192+
193+
```python
194+
from together import Together
195+
196+
client = Together()
197+
198+
response = client.chat.completions.create(
199+
model="meta-llama/Llama-3.2-3B-Instruct-Turbo",
200+
messages=[{"role": "user", "content": "tell me about new york"}],
201+
logprobs=1
202+
)
203+
204+
response_lobprobs = response.choices[0].logprobs
205+
206+
print(dict(zip(response_lobprobs.tokens, response_lobprobs.token_logprobs)))
207+
# {'New': -2.384e-07, ' York': 0.0, ',': 0.0, ' also': -0.20703125, ' known': -0.20214844, ' as': -8.34465e-07, ... }
208+
```
209+
210+
More details about using logprobs in Together's API can be found [here](https://docs.together.ai/docs/logprobs).
211+
212+
189213
### Completions
190214

191215
Completions are for code and language models shown [here](https://docs.together.ai/docs/inference-models). Below, a code model example is shown.
@@ -323,7 +347,7 @@ client.files.delete(id="file-d0d318cb-b7d9-493a-bd70-1cfe089d3815") # deletes a
323347

324348
### Fine-tunes
325349

326-
The finetune API is used for fine-tuning and allows developers to create finetuning jobs. It also has several methods to list all jobs, retrive statuses and get checkpoints. Please refer to our fine-tuning docs [here](https://docs.together.ai/docs/fine-tuning-python).
350+
The finetune API is used for fine-tuning and allows developers to create finetuning jobs. It also has several methods to list all jobs, retrive statuses and get checkpoints. Please refer to our fine-tuning docs [here](https://docs.together.ai/docs/fine-tuning-quickstart).
327351

328352
```python
329353
from together import Together
@@ -332,7 +356,7 @@ client = Together()
332356

333357
client.fine_tuning.create(
334358
training_file = 'file-d0d318cb-b7d9-493a-bd70-1cfe089d3815',
335-
model = 'mistralai/Mixtral-8x7B-Instruct-v0.1',
359+
model = 'meta-llama/Llama-3.2-3B-Instruct',
336360
n_epochs = 3,
337361
n_checkpoints = 1,
338362
batch_size = "max",
@@ -362,6 +386,33 @@ for model in models:
362386
print(model)
363387
```
364388

389+
### Batch Inference
390+
391+
The batch API allows you to submit larger inference jobs for completion with a 24 hour turn-around time, below is an example. To learn more refer to the [docs here](https://docs.together.ai/docs/batch-inference).
392+
393+
```python
394+
from together import Together
395+
396+
client = Together()
397+
398+
# Upload the batch file
399+
batch_file = client.files.upload(file="simpleqa_batch_student.jsonl", purpose="batch-api")
400+
401+
# Create the batch job
402+
batch = client.batches.create_batch(file_id=batch_file.id, endpoint="/v1/chat/completions")
403+
404+
# Monitor the batch status
405+
batch_stat = client.batches.get_batch(batch.id)
406+
407+
# List all batches - contains other batches as well
408+
client.batches.list_batches()
409+
410+
# Download the file content if job completed
411+
if batch_stat.status == 'COMPLETED':
412+
output_response = client.files.retrieve_content(id=batch_stat.output_file_id,
413+
output="simpleqa_v3_output.jsonl")
414+
```
415+
365416
## Usage – CLI
366417

367418
### Chat Completions
@@ -370,7 +421,7 @@ for model in models:
370421
together chat.completions \
371422
--message "system" "You are a helpful assistant named Together" \
372423
--message "user" "What is your name?" \
373-
--model mistralai/Mixtral-8x7B-Instruct-v0.1
424+
--model meta-llama/Llama-4-Scout-17B-16E-Instruct
374425
```
375426

376427
The Chat Completions CLI enables streaming tokens to stdout by default. To disable streaming, use `--no-stream`.
@@ -380,7 +431,7 @@ The Chat Completions CLI enables streaming tokens to stdout by default. To disab
380431
```bash
381432
together completions \
382433
"Large language models are " \
383-
--model mistralai/Mixtral-8x7B-v0.1 \
434+
--model meta-llama/Llama-4-Scout-17B-16E-Instruct \
384435
--max-tokens 512 \
385436
--stop "."
386437
```

0 commit comments

Comments
 (0)