ModelCatalog is the main class responsible for model lookup of (1) Model Card and (2) Finding Model Class. In most cases, ModelCatalog is the interface for all facets of interacting with the model classes.
| 510 | |
| 511 | |
| 512 | class ModelCatalog: |
| 513 | |
| 514 | """ ModelCatalog is the main class responsible for model lookup of (1) Model Card and (2) Finding Model Class. |
| 515 | In most cases, ModelCatalog is the interface for all facets of interacting with the model classes. |
| 516 | """ |
| 517 | |
| 518 | def __init__(self): |
| 519 | |
| 520 | # ModelCatalog is simple, flexible mechanism to track registered models |
| 521 | # Easy to create "model repo" with mix of model types and instantiation approaches |
| 522 | # Builds on standard model classes with standard inference |
| 523 | |
| 524 | self.model_classes = _ModelRegistry().get_model_classes() |
| 525 | |
| 526 | self.global_model_list = _ModelRegistry().get_model_list() |
| 527 | |
| 528 | self.base_attributes = _ModelRegistry().get_model_catalog_vars() |
| 529 | |
| 530 | self.account_name = None |
| 531 | self.library_name= None |
| 532 | |
| 533 | # attributes that are used when a model is selected through .load_model method |
| 534 | self.loaded_model_name = None |
| 535 | self.loaded_model_class = None |
| 536 | self.temperature = 0.3 |
| 537 | self.use_gpu = True |
| 538 | self.sample = True |
| 539 | self.max_output = 100 |
| 540 | self.get_logits = False |
| 541 | self.force_reload = False |
| 542 | self.api_endpoint = None |
| 543 | |
| 544 | self.selected_model = None |
| 545 | self.api_key= None |
| 546 | self.custom_loader = None |
| 547 | |
| 548 | # new - add - 102024 |
| 549 | self.model_kwargs = {} |
| 550 | |
| 551 | def to_state_dict(self): |
| 552 | |
| 553 | """ Writes selected model state parameters to dictionary. """ |
| 554 | |
| 555 | state_dict = {} |
| 556 | for keys in self.base_attributes: |
| 557 | if hasattr(self, keys): |
| 558 | state_dict.update({keys: getattr(self, keys)}) |
| 559 | |
| 560 | return state_dict |
| 561 | |
| 562 | def pull_latest_manifest(self): |
| 563 | """ Not implemented currently """ |
| 564 | # will add to check manifest in global repo and make available for pull down |
| 565 | return 0 |
| 566 | |
| 567 | def reset_to_default_catalog(self): |
| 568 | """ Resets model catalog to default list in model_configs """ |
| 569 |
no outgoing calls