nos.common.spec
nos.common.spec.FunctionSignature ¶
Function signature that fully describes the remote-model to be executed
including inputs
, outputs
, func_or_cls
to be executed,
initialization args
/kwargs
.
Source code in nos/common/spec.py
27 28 29 30 31 32 33 34 35 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 |
|
init_args
class-attribute
instance-attribute
¶
Arguments to initialize the model instance.
init_kwargs
class-attribute
instance-attribute
¶
Keyword arguments to initialize the model instance.
input_annotations
class-attribute
instance-attribute
¶
Mapping of input keyword arguments to dtypes.
output_annotations
class-attribute
instance-attribute
¶
Mapping of output names to dtypes.
parameters
class-attribute
instance-attribute
¶
Input function signature (as returned by inspect.signature).
return_annotation
class-attribute
instance-attribute
¶
Output / return function signature (as returned by inspect.signature).
validate
staticmethod
¶
Validate the input dict against the defined signature (input or output).
Source code in nos/common/spec.py
nos.common.spec.ModelSpec ¶
Model specification for the registry.
ModelSpec captures all the relevant information for the instantiation, runtime and execution of a model.
Source code in nos/common/spec.py
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 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
|
signature
class-attribute
instance-attribute
¶
signature: Dict[str, FunctionSignature] = Field(default_factory=dict)
Model function signatures to export (method -> FunctionSignature).
runtime_env
class-attribute
instance-attribute
¶
Runtime environment with custom packages.
default_signature
cached
property
¶
default_signature: FunctionSignature
Return the default function signature.
Returns:
-
FunctionSignature
(FunctionSignature
) –Default function signature.
task ¶
task(method: str = None) -> TaskType
Return the task type for a given method (or defaults to default method).
Source code in nos/common/spec.py
metadata ¶
Return the model spec metadata for a given method (or defaults to default method).
Source code in nos/common/spec.py
set_default_method ¶
Set the default method name.
Source code in nos/common/spec.py
__call__ ¶
Create a model instance.
This method allows us to create a model instance directly from the model spec. Let's consider the example below
```
class CustomModel:
...
CustomModel = ModelSpec.from_cls(CustomModel)
model = CustomModel(*init_args, **init_kwargs)
```
Parameters:
-
*init_args
–Positional arguments.
-
**init_kwargs
–Keyword arguments.
Returns: Any: Model instance.
Source code in nos/common/spec.py
from_cls
classmethod
¶
from_cls(func_or_cls: Callable, init_args: Tuple[Any, ...] = (), init_kwargs: Dict[str, Any] = {}, method: str = '__call__', runtime_env: RuntimeEnv = None, model_id: str = None, **kwargs: Any) -> ModelSpec
Wrap custom models/classes into a nos-compatible model spec.
Parameters:
-
func_or_cls
(Callable
) –Model function or class. For now, only classes are supported.
-
init_args
(Tuple[Any, ...]
, default:()
) –Initialization arguments.
-
init_kwargs
(Dict[str, Any]
, default:{}
) –Initialization keyword arguments.
-
method
(str
, default:'__call__'
) –Method name to be executed.
-
runtime_env
(RuntimeEnv
, default:None
) –Runtime environment specification.
-
model_id
(str
, default:None
) –Optional model identifier.
-
**kwargs
(Any
, default:{}
) –Additional keyword arguments. These include
init_args
andinit_kwargs
to initialize the model instance.
Returns:
-
ModelSpec
(ModelSpec
) –The resulting model specification that fully describes the model execution.