ezpz.examples.deepspeed.tp.utilsΒΆ
Utility helpers for DeepSpeed tensor-parallel scripts (OpenAI completions, IO).
This module is imported by other examples; it is not a standalone CLI.
OpenAIDecodingArguments
dataclass
ΒΆ
Configurable decoding parameters for OpenAI API completions.
Source code in src/ezpz/examples/deepspeed/tp/utils.py
jdump(obj, f, mode='w', indent=4, default=None)
ΒΆ
Dump a str or dictionary to a file in json format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
An object to be written. |
required |
f
|
str | PathLike
|
A string path to the location on disk. |
required |
mode
|
str
|
Mode for opening the file. |
'w'
|
indent
|
int
|
Indent for storing json dictionaries. |
4
|
default
|
Any | None
|
A function to handle non-serializable entries; defaults to |
None
|
Source code in src/ezpz/examples/deepspeed/tp/utils.py
jload(f, mode='r')
ΒΆ
openai_completion(prompts, decoding_args, model_name='text-davinci-003', sleep_time=2, batch_size=1, max_instances=sys.maxsize, max_batches=sys.maxsize, return_text=False, **decoding_kwargs)
ΒΆ
Decode with OpenAI API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompts
|
str | Sequence[str] | Sequence[dict[str, str]] | dict[str, str]
|
A string or a list of strings to complete. If it is a chat model the strings should be formatted as explained here: https://github.com/openai/openai-python/blob/main/chatml.md. If it is a chat model it can also be a dictionary (or list thereof) as explained here: https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb |
required |
decoding_args
|
OpenAIDecodingArguments
|
Decoding arguments. |
required |
model_name
|
str
|
Model name. Can be either in the format of "org/model" or just "model". |
'text-davinci-003'
|
sleep_time
|
int
|
Time to sleep once the rate-limit is hit. |
2
|
batch_size
|
int
|
Number of prompts to send in a single request. Only for non chat model. |
1
|
max_instances
|
int
|
Maximum number of prompts to decode. |
maxsize
|
max_batches
|
int
|
Maximum number of batches to decode. This argument will be deprecated in the future. |
maxsize
|
return_text
|
bool
|
If True, return text instead of full completion object (which contains things like logprob). |
False
|
decoding_kwargs
|
dict[Any, Any]
|
Additional decoding arguments. Pass in |
{}
|
Returns:
| Type | Description |
|---|---|
Union[Union[str, Any], Sequence[StrOrOpenAIObject], Sequence[Sequence[StrOrOpenAIObject]]]
|
A completion or a list of completions. |
Union[Union[str, Any], Sequence[StrOrOpenAIObject], Sequence[Sequence[StrOrOpenAIObject]]]
|
Depending on return_text, return_openai_object, and decoding_args.n, the completion type can be one of - a string (if return_text is True) - an openai_object.OpenAIObject object (if return_text is False) - a list of objects of the above types (if decoding_args.n > 1) |
Source code in src/ezpz/examples/deepspeed/tp/utils.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |