MCPcopy Create free account
hub / github.com/tdrussell/diffusion-pipe / ModelWrapper

Class ModelWrapper

models/base.py:451–464  ·  view source on GitHub ↗

Simple wrapper that delays loading the model, since the model isn't needed if the training data is already cached.

Source from the content-addressed store, hash-verified

449
450
451class ModelWrapper:
452 '''Simple wrapper that delays loading the model, since the model isn't needed if the training data is already cached.'''
453 def __init__(self, load_fn):
454 self._load_fn = load_fn
455 self._model = None
456
457 def __getattr__(self, name):
458 if self._model is None:
459 raise RuntimeError("Model wasn't loaded, this shouldn't ever happen.")
460 return getattr(self._model, name)
461
462 def load_model_if_needed(self):
463 if self._model is None:
464 self._model = self._load_fn()
465
466
467def tokenize_with_weights(self, text:str, return_word_ids=False, **kwargs):

Callers 2

__init__Method · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected