together 0.2.6__py3-none-any.whl → 0.2.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- together/__init__.py +6 -0
- together/cli/cli.py +2 -1
- together/commands/embeddings.py +48 -0
- together/embeddings.py +35 -0
- {together-0.2.6.dist-info → together-0.2.7.dist-info}/METADATA +50 -7
- {together-0.2.6.dist-info → together-0.2.7.dist-info}/RECORD +9 -7
- {together-0.2.6.dist-info → together-0.2.7.dist-info}/WHEEL +1 -1
- {together-0.2.6.dist-info → together-0.2.7.dist-info}/LICENSE +0 -0
- {together-0.2.6.dist-info → together-0.2.7.dist-info}/entry_points.txt +0 -0
together/__init__.py
CHANGED
|
@@ -16,9 +16,11 @@ api_base_complete = urllib.parse.urljoin(api_base, "/api/inference")
|
|
|
16
16
|
api_base_files = urllib.parse.urljoin(api_base, "/v1/files/")
|
|
17
17
|
api_base_finetune = urllib.parse.urljoin(api_base, "/v1/fine-tunes/")
|
|
18
18
|
api_base_instances = urllib.parse.urljoin(api_base, "instances/")
|
|
19
|
+
api_base_embeddings = urllib.parse.urljoin(api_base, "api/v1/embeddings")
|
|
19
20
|
|
|
20
21
|
default_text_model = "togethercomputer/RedPajama-INCITE-7B-Chat"
|
|
21
22
|
default_image_model = "runwayml/stable-diffusion-v1-5"
|
|
23
|
+
default_embedding_model = "togethercomputer/bert-base-uncased"
|
|
22
24
|
log_level = "WARNING"
|
|
23
25
|
|
|
24
26
|
MISSING_API_KEY_MESSAGE = """TOGETHER_API_KEY not found.
|
|
@@ -31,6 +33,7 @@ BACKOFF_FACTOR = 0.2
|
|
|
31
33
|
min_samples = 100
|
|
32
34
|
|
|
33
35
|
from .complete import Complete
|
|
36
|
+
from .embeddings import Embeddings
|
|
34
37
|
from .error import *
|
|
35
38
|
from .files import Files
|
|
36
39
|
from .finetune import Finetune
|
|
@@ -45,13 +48,16 @@ __all__ = [
|
|
|
45
48
|
"api_base_files",
|
|
46
49
|
"api_base_finetune",
|
|
47
50
|
"api_base_instances",
|
|
51
|
+
"api_base_embeddings",
|
|
48
52
|
"default_text_model",
|
|
49
53
|
"default_image_model",
|
|
54
|
+
"default_embedding_model",
|
|
50
55
|
"Models",
|
|
51
56
|
"Complete",
|
|
52
57
|
"Files",
|
|
53
58
|
"Finetune",
|
|
54
59
|
"Image",
|
|
60
|
+
"Embeddings",
|
|
55
61
|
"MAX_CONNECTION_RETRIES",
|
|
56
62
|
"MISSING_API_KEY_MESSAGE",
|
|
57
63
|
"BACKOFF_FACTOR",
|
together/cli/cli.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import argparse
|
|
3
3
|
|
|
4
4
|
import together
|
|
5
|
-
from together.commands import chat, complete, files, finetune, image, models
|
|
5
|
+
from together.commands import chat, complete, embeddings, files, finetune, image, models
|
|
6
6
|
from together.utils import get_logger
|
|
7
7
|
|
|
8
8
|
|
|
@@ -49,6 +49,7 @@ def main() -> None:
|
|
|
49
49
|
image.add_parser(subparser)
|
|
50
50
|
files.add_parser(subparser)
|
|
51
51
|
finetune.add_parser(subparser)
|
|
52
|
+
embeddings.add_parser(subparser)
|
|
52
53
|
|
|
53
54
|
args = parser.parse_args()
|
|
54
55
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
import together
|
|
7
|
+
from together import Embeddings
|
|
8
|
+
from together.utils import get_logger
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
logger = get_logger(str(__name__))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def add_parser(subparsers: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
|
|
15
|
+
COMMAND_NAME = "embeddings"
|
|
16
|
+
subparser = subparsers.add_parser(COMMAND_NAME)
|
|
17
|
+
|
|
18
|
+
subparser.add_argument(
|
|
19
|
+
"input",
|
|
20
|
+
metavar="INPUT",
|
|
21
|
+
default=None,
|
|
22
|
+
type=str,
|
|
23
|
+
help="A string providing context for the model to embed",
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
subparser.add_argument(
|
|
27
|
+
"--model",
|
|
28
|
+
"-m",
|
|
29
|
+
default=together.default_embedding_model,
|
|
30
|
+
type=str,
|
|
31
|
+
help=f"The name of the model to query. Default={together.default_text_model}",
|
|
32
|
+
)
|
|
33
|
+
subparser.set_defaults(func=_run_complete)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _run_complete(args: argparse.Namespace) -> None:
|
|
37
|
+
embeddings = Embeddings()
|
|
38
|
+
|
|
39
|
+
try:
|
|
40
|
+
response = embeddings.create(
|
|
41
|
+
input=args.input,
|
|
42
|
+
model=args.model,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
print(json.dumps(response, indent=4))
|
|
46
|
+
except together.AuthenticationError:
|
|
47
|
+
logger.critical(together.MISSING_API_KEY_MESSAGE)
|
|
48
|
+
exit(0)
|
together/embeddings.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
|
+
|
|
3
|
+
import together
|
|
4
|
+
from together.utils import create_post_request, get_logger
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
logger = get_logger(str(__name__))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Embeddings:
|
|
11
|
+
@classmethod
|
|
12
|
+
def create(
|
|
13
|
+
self,
|
|
14
|
+
input: str,
|
|
15
|
+
model: Optional[str] = "",
|
|
16
|
+
) -> Dict[str, Any]:
|
|
17
|
+
if model == "":
|
|
18
|
+
model = together.default_embedding_model
|
|
19
|
+
|
|
20
|
+
parameter_payload = {
|
|
21
|
+
"input": input,
|
|
22
|
+
"model": model,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
# send request
|
|
26
|
+
response = create_post_request(
|
|
27
|
+
url=together.api_base_embeddings, json=parameter_payload
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
response_json = dict(response.json())
|
|
32
|
+
|
|
33
|
+
except Exception as e:
|
|
34
|
+
raise together.JSONError(e, http_status=response.status_code)
|
|
35
|
+
return response_json
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: together
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: Python client for Together's Cloud Platform!
|
|
5
5
|
Home-page: https://github.com/togethercomputer/together
|
|
6
6
|
License: Apache-2.0
|
|
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.8
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.9
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.10
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
19
|
Requires-Dist: requests (>=2.31.0,<3.0.0)
|
|
19
20
|
Requires-Dist: sseclient-py (>=1.7.2,<2.0.0)
|
|
20
21
|
Requires-Dist: tabulate (>=0.9.0,<0.10.0)
|
|
@@ -353,7 +354,34 @@ Job creation details:
|
|
|
353
354
|
Do you want to submit the job? [y/N]
|
|
354
355
|
```
|
|
355
356
|
|
|
356
|
-
|
|
357
|
+
Here is an example of only part of the `resp` response to highlight some of the useful information about your finetune job.
|
|
358
|
+
|
|
359
|
+
```
|
|
360
|
+
{ 'Suffix': 'my-demo-finetune',
|
|
361
|
+
'batch_size': 4,
|
|
362
|
+
'created_at': '2023-11-07T19:04:30.579Z',
|
|
363
|
+
'enable_checkpoints': False,
|
|
364
|
+
'epochs_completed': 0,
|
|
365
|
+
'events': [ { 'checkpoint_path': '',
|
|
366
|
+
'created_at': '2023-11-07T19:04:30.579Z',
|
|
367
|
+
'hash': '',
|
|
368
|
+
'level': '',
|
|
369
|
+
'message': 'Fine tune request created',
|
|
370
|
+
'model_path': '',
|
|
371
|
+
'object': 'fine-tune-event',
|
|
372
|
+
'param_count': 0,
|
|
373
|
+
'token_count': 0,
|
|
374
|
+
'training_offset': 0,
|
|
375
|
+
'type': 'JOB_PENDING',
|
|
376
|
+
'wandb_url': ''}],
|
|
377
|
+
'id': 'ft-494cbd75-3057-44b4-8186-045c14be8d03',
|
|
378
|
+
'learning_rate': 1e-05,
|
|
379
|
+
'model': 'togethercomputer/RedPajama-INCITE-Chat-3B-v1',
|
|
380
|
+
'model_output_name': 'carson/RedPajama-INCITE-Chat-3B-v1-my-demo-finetune-2023-11-07-19-04-30',
|
|
381
|
+
'wandb_url': '...'}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
The response `resp` has alot of information for you that you can retrieve again later with `together.Finetune.retrieve` using the `fine_tune_id` for this job. You can find this `fine_tune_id` in `resp['id']` and use it to check in on how your finetune job is doing.
|
|
357
385
|
|
|
358
386
|
```python
|
|
359
387
|
print(together.Finetune.retrieve(fine_tune_id=fine_tune_id)) # retrieves information on finetune event
|
|
@@ -362,14 +390,16 @@ print(together.Finetune.is_final_model_available(fine_tune_id=fine_tune_id)) # T
|
|
|
362
390
|
print(together.Finetune.get_checkpoints(fine_tune_id=fine_tune_id)) # list of checkpoints
|
|
363
391
|
```
|
|
364
392
|
|
|
365
|
-
The `get_job_status` should change from `pending` to `running` to `completed` as `is_final_model_available` changes from `False` to `True`. Once the
|
|
393
|
+
The `get_job_status` should change from `pending` to `running` to `completed` as `is_final_model_available` changes from `False` to `True`. Once in the `running` state, you can retrieve the `wandb_url` and visit this page to monitor the learning progress of this finetune job.
|
|
366
394
|
|
|
367
|
-
`
|
|
395
|
+
Under `model_output_name` you will find the unique name that will be given to the new finetuned model whose creation is underway. This name includes your username, the base model name, your suffix and the datetime the job was created. In addition to using the API to track the status as shown above, you can use `model_output_name` to find helpful features related to the new model within the Jobs section of your account on our webpage.
|
|
396
|
+
|
|
397
|
+
Once the final model is available, you should be able to see your new model under `together.Models.list()` under `model_output_name`.
|
|
368
398
|
|
|
369
399
|
Now you can download your model using `together.Finetune.download(fine_tune_id)` or start using your model on our inference engine (may take a few minutes after finetuning to become available) by first starting your new model instance:
|
|
370
400
|
|
|
371
401
|
```
|
|
372
|
-
together.Models.start(
|
|
402
|
+
together.Models.start(model_output_name)
|
|
373
403
|
```
|
|
374
404
|
|
|
375
405
|
then calling it to do completions:
|
|
@@ -377,14 +407,14 @@ then calling it to do completions:
|
|
|
377
407
|
```
|
|
378
408
|
output = together.Complete.create(
|
|
379
409
|
prompt = "Isaac Asimov's Three Laws of Robotics are:\n\n1. ",
|
|
380
|
-
model =
|
|
410
|
+
model = model_output_name,
|
|
381
411
|
)
|
|
382
412
|
```
|
|
383
413
|
|
|
384
414
|
To check whether your model is finished deploying, you can use the `Models.ready` like so:
|
|
385
415
|
|
|
386
416
|
```
|
|
387
|
-
together.Models.ready(
|
|
417
|
+
together.Models.ready(model_output_name)
|
|
388
418
|
```
|
|
389
419
|
|
|
390
420
|
```
|
|
@@ -450,6 +480,16 @@ print(output_text)
|
|
|
450
480
|
Space Robots are a great way to get your kids interested in science. After all, they are the future!
|
|
451
481
|
```
|
|
452
482
|
|
|
483
|
+
## Embeddings API
|
|
484
|
+
|
|
485
|
+
Embeddings are vector representations of sequences. You can use these vectors for measuring the overall similarity between texts. Embeddings are useful for tasks such as search and retrieval.
|
|
486
|
+
|
|
487
|
+
```python
|
|
488
|
+
resp = together.Embeddings.create("embed this sentence into a single vector", model="togethercomputer/bert-base-uncased")
|
|
489
|
+
|
|
490
|
+
print(resp['data'][0]['embedding']) # [0.06659205, 0.07896972, 0.007910785 ........]
|
|
491
|
+
```
|
|
492
|
+
|
|
453
493
|
## Colab Tutorial
|
|
454
494
|
|
|
455
495
|
Follow along in our Colab (Google Colaboratory) Notebook Tutorial [Example Finetuning Project](https://colab.research.google.com/drive/11DwtftycpDSgp3Z1vnV-Cy68zvkGZL4K?usp=sharing).
|
|
@@ -509,6 +549,9 @@ together finetune download ft-dd93c727-f35e-41c2-a370-7d55b54128fa
|
|
|
509
549
|
|
|
510
550
|
# inference using your new finetuned model (with new finetuned model name from together models list)
|
|
511
551
|
together complete "Space robots are" -m yourname/ft-dd93c727-f35e-41c2-a370-7d55b54128fa-2023-08-16-10-15-09
|
|
552
|
+
|
|
553
|
+
# create an embedding from your input sequence
|
|
554
|
+
together embeddings "embed this sentence into a single vector" -m togethercomputer/bert-base-uncased
|
|
512
555
|
```
|
|
513
556
|
|
|
514
557
|
## Contributing
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
together/__init__.py,sha256
|
|
1
|
+
together/__init__.py,sha256=vhGyzirz_S-3sUHvLX4cL-xlzL1439chQcJI-3fjXww,1697
|
|
2
2
|
together/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
together/cli/cli.py,sha256=
|
|
3
|
+
together/cli/cli.py,sha256=aALVTU7hhPdiSm0P175UXCwkBphP5DMi3mLEJ10K-1o,1655
|
|
4
4
|
together/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
together/commands/chat.py,sha256=5hcTGiS0er7WO5UpFnIkWnOwWFZfppQ_5RvExVgkz30,4297
|
|
6
6
|
together/commands/complete.py,sha256=ndm9hdTcnav4uetgmvIfTdtwTthshX2LOvx-f46pU58,5512
|
|
7
|
+
together/commands/embeddings.py,sha256=HzBh_SNtlmeUH3RuCNhPCLPjw1X_gSKgPu6-lRqs3P4,1181
|
|
7
8
|
together/commands/files.py,sha256=nlM21PIklCD1ebc9Vlw5KKr8tyqwwfS4zw5BEj9UXAg,5890
|
|
8
9
|
together/commands/finetune.py,sha256=4f-VZWnfZeRs39MvTnu_kYpoI53bpSmYtVbboY4N-C8,11240
|
|
9
10
|
together/commands/image.py,sha256=2JWI597OO77nPJR9cBiJspZ74ijrCtZgcAF538H_AMA,4007
|
|
10
11
|
together/commands/models.py,sha256=MOkn_IZw4NnhnQyFHAmRvXsqT9_tz26xLTD7mTuDO_E,6201
|
|
11
12
|
together/complete.py,sha256=iM9DRxK5zDIqM7vcbfwymLTZ0YSSXpfj8Ks2O3A8xnM,3356
|
|
13
|
+
together/embeddings.py,sha256=v7p4lSS6wQf6e2jncBeJQg3l-e6ae4kgVrMnvIfmnN8,815
|
|
12
14
|
together/error.py,sha256=OlEuDG1E-O__fvKpwQ3mL3QxGNJ-OsMgmKwp-aJiG-4,2631
|
|
13
15
|
together/files.py,sha256=1NFojMHHV8HfND2NmMVHhZcQljRM-iMLwXocnMJBRt0,12256
|
|
14
16
|
together/finetune.py,sha256=VwYbhSwqwh0emCanHCoFTA9yu1zg4-0tBQQH9KFxfdA,12187
|
|
@@ -18,8 +20,8 @@ together/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
18
20
|
together/tools/conversation.py,sha256=m_rt0VBkpweHV0DXZwQmaXeGGfnUr96fHqdRjabfLBk,1859
|
|
19
21
|
together/utils.py,sha256=as0HrLpkEei223IvKue0GujCKmjLn6EISxm1mq8tnEk,5268
|
|
20
22
|
together/version.py,sha256=p03ivHyE0SyWU4jAnRTBi_sOwywVWoZPU4g2gzRgG-Y,126
|
|
21
|
-
together-0.2.
|
|
22
|
-
together-0.2.
|
|
23
|
-
together-0.2.
|
|
24
|
-
together-0.2.
|
|
25
|
-
together-0.2.
|
|
23
|
+
together-0.2.7.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
24
|
+
together-0.2.7.dist-info/METADATA,sha256=XILawH21LHgLb_fsvm-vgtS59LMzFcmkN8bymAfSDWk,27029
|
|
25
|
+
together-0.2.7.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
26
|
+
together-0.2.7.dist-info/entry_points.txt,sha256=G-b5NKW6lUUf1V1fH8IPTBb7jXnK7lhbX9H1zTEJXPs,50
|
|
27
|
+
together-0.2.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|