serve.serve_engine.serve
EasyServe
Source code in src/python/easydel/serve/serve_engine/serve.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
|
__repr__()
The repr function is used to generate a string representation of an object. This function should return a string that can be parsed by the Python interpreter to recreate the object. The repr function is called when you use print() on an object, or when you type its name in the REPL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Refer to the instance of the class |
required |
Returns:
Type | Description |
---|---|
A string representation of the object |
Source code in src/python/easydel/serve/serve_engine/serve.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
|
__str__()
The str function is called when you use the print function or when str() is used. It should return a string representation of the object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Refer to the instance of the class |
required |
Returns:
Type | Description |
---|---|
The object's string representation |
Source code in src/python/easydel/serve/serve_engine/serve.py
489 490 491 492 493 494 495 496 497 498 |
|
compile(verbose=True)
The compile function is used to compile the model for use in inference. It does this by running through all possible combinations of rules and actions, and compiling them into functions that can be called later on during inference. This allows us to avoid having to recompile the model every time we want to run it, which would be very slow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Represent the instance of the class |
required | |
verbose |
bool
|
bool: Print out the compiling process |
True
|
Returns:
Type | Description |
---|---|
bool
|
True, but what does it do? |
Source code in src/python/easydel/serve/serve_engine/serve.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
|
conversation_template(conversation)
The conversation_template function takes a list of ConversationItem objects and returns a string. where system message, user message, and assistant message are the content fields of the ConversationItem objects. If there is no system message in the conversation, then it will be omitted from the template.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Refer to the current instance of a class |
required | |
conversation |
List[Dict]
|
List[ConversationItem]: Pass in the conversation items |
required |
Returns:
Type | Description |
---|---|
str
|
A string that is a concatenation of the messages in the conversation |
Source code in src/python/easydel/serve/serve_engine/serve.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
create_generation_functions_and_tokenizers(model, tokenizer, serve_config, partition_specs)
staticmethod
The create_generation_functions_and_tokenizers function is used to create the functions that will be used for generation. It also creates a tokenizer object that can be used to encode and decode text. The function takes in a model, a tokenizer, an EasyServeConfig object (which contains all the parameters needed for generation), and partition_specs which are specifications about how data should be partitioned across devices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
EasyDeLFlaxPretrainedModel
|
EasyDeLFlaxPretrainedModel: Create the model and tokenizer |
required |
tokenizer |
PreTrainedTokenizerBase
|
PreTrainedTokenizerBase: Create a tokenizer object |
required |
serve_config |
EasyServeConfig
|
EasyServeConfig: Create the generation function |
required |
partition_specs |
dict[str, PartitionSpec]
|
dict[str, PartitionSpec]: Specify the sharding of the model parameters |
required |
Returns:
Type | Description |
---|---|
LLMBaseReq
|
An LLMBaseReq object |
Source code in src/python/easydel/serve/serve_engine/serve.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|
create_shard_and_gather_functions(parameters, partition_rules, dtype='fp16')
staticmethod
The create_shard_and_gather_functions function takes in a dictionary of parameters, a tuple of partition rules, and an optional dtype. It then matches the partition rules to the parameters and creates shard functions for each parameter. The shard functions are used to split up a parameter into shards (or partitions) that can be stored on different devices. The gather function is used to combine all the shards back together again.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters |
dict
|
dict: Specify the parameters of the model |
required |
partition_rules |
Tuple[Tuple[str, PartitionSpec]]
|
Tuple[Tuple[str, PartitionSpec]]: Specify which parameters to partition |
required |
dtype |
Union[dtype, str]
|
jax.numpy.dtype | str: Specify the data type of the parameters |
'fp16'
|
Returns:
Type | Description |
---|---|
A tuple of three elements: |
Source code in src/python/easydel/serve/serve_engine/serve.py
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 |
|
from_parameters(llm, params, tokenizer, serve_config, partition_rules, shard_parameters=True)
classmethod
The from_parameters function is the main entry point for creating a model that can be served. It takes in a pretrained model, parameters, tokenizer and serve_config as input and returns an object of type EasyServe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cls |
Create a new instance of the class |
required | |
llm |
EasyDeLFlaxPretrainedModel
|
EasyDeLFlaxPretrainedModel: Pass the model to the class |
required |
params |
dict
|
dict: Pass the parameters of the model |
required |
tokenizer |
PreTrainedTokenizerBase
|
PreTrainedTokenizerBase: Create the tokenizer and prefix_tokenizer |
required |
serve_config |
EasyServeConfig
|
EasyServeConfig: Configure the model for serving |
required |
partition_rules |
Tuple[Tuple[str, PartitionSpec]]
|
Tuple[Tuple[str, PartitionSpec]]: Partition the parameters of the model |
required |
shard_parameters |
bool
|
bool: Specify whether the parameters should be sharded or not |
True
|
|
Shard the parameters of the model |
required |
Returns:
Type | Description |
---|---|
A EasyServe object |
Source code in src/python/easydel/serve/serve_engine/serve.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
sample(string, *, greedy=False, max_new_tokens=None, **kwargs)
The process function is the main function of a model. It takes in an input string and returns a list of strings that are generated from that input string. The process function can be called multiple times with different inputs, and each time it will return a new set of outputs based on those inputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
Access the class attributes |
required | |
string |
str
|
str: Pass the string that we want to generate |
required |
greedy |
bool
|
bool: Determine whether to use the greedy or non-greedy version of the generate function |
False
|
max_new_tokens |
int
|
int: Set the number of tokens to generate |
None
|
kwargs |
Pass any additional parameters to the process function |
{}
|
Returns:
Type | Description |
---|---|
A generator that yields the predicted text and the number of tokens generated |
Source code in src/python/easydel/serve/serve_engine/serve.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
|
shard_parameters(mesh, params, partition_rules, serve_config)
staticmethod
The shard_parameters function takes a set of parameters and partitions them according to the partition_rules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mesh |
Mesh
|
Mesh: Create a mesh object that is used to shard the parameters |
required |
params |
Union[FrozenDict, dict]
|
FrozenDict | dict: Pass in the parameters of the model |
required |
partition_rules |
Tuple[Tuple[str, PartitionSpec]]
|
Tuple[Tuple[str, PartitionSpec]]: Specify the partitioning rules for each parameter |
required |
serve_config |
EasyServeConfig
|
EasyServeConfig: Specify the dtype of the parameters |
required |
|
Create a mesh of devices |
required |
Returns:
Type | Description |
---|---|
sharded parameters |
Source code in src/python/easydel/serve/serve_engine/serve.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|