-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Moved model loader to separate class, injected into basemodel udf and changed test setup accordingly * moved last_created_pipeline back * security update
- Loading branch information
1 parent
ec5cabd
commit 4629152
Showing
6 changed files
with
134 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Transformers Extension 0.7.0, released T.B.D | ||
|
||
Code name: T.B.D | ||
|
||
|
||
## Summary | ||
|
||
T.B.D | ||
|
||
### Features | ||
|
||
### Bug Fixes | ||
|
||
### Refactorings | ||
|
||
- #144: Extracted base_model_udf.load_models into separate class | ||
|
||
|
||
### Documentation | ||
|
||
|
||
|
||
### Security | ||
- #144: Updated Cryptography to version 41.0.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import torch | ||
|
||
class LoadModel: | ||
def __init__(self, | ||
pipeline, | ||
base_model, | ||
tokenizer, | ||
task_name, | ||
device | ||
): | ||
self.pipeline = pipeline | ||
self.base_model = base_model | ||
self.tokenizer = tokenizer | ||
self.task_name = task_name | ||
self.device = device | ||
self.last_loaded_model = None | ||
self.last_loaded_tokenizer = None | ||
self.last_loaded_model_key = None | ||
|
||
def load_models(self, model_name: str, | ||
current_model_key, | ||
cache_dir, | ||
token_conn_obj) -> None: | ||
""" | ||
Load model and tokenizer model from the cached location in bucketfs. | ||
If the desired model is not cached, this method will attempt to | ||
download the model to the read-only path /bucket/.. and cause an error. | ||
This error will be addressed in ticket | ||
https://github.com/exasol/transformers-extension/issues/43. | ||
:param model_name: The model name to be loaded | ||
""" | ||
token = False | ||
if token_conn_obj: | ||
token = token_conn_obj.password | ||
|
||
self.last_loaded_model = self.base_model.from_pretrained( | ||
model_name, cache_dir=cache_dir, use_auth_token=token) | ||
self.last_loaded_tokenizer = self.tokenizer.from_pretrained( | ||
model_name, cache_dir=cache_dir, use_auth_token=token) | ||
last_created_pipeline = self.pipeline( | ||
self.task_name, | ||
model=self.last_loaded_model, | ||
tokenizer=self.last_loaded_tokenizer, | ||
device=self.device, | ||
framework="pt") | ||
self.last_loaded_model_key = current_model_key | ||
return last_created_pipeline | ||
|
||
def clear_device_memory(self): | ||
""" | ||
Delete models and free device memory | ||
""" | ||
self.last_loaded_model = None | ||
self.last_loaded_tokenizer = None | ||
torch.cuda.empty_cache() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters