From e0c5564244e7489c00a959ca20b4e0f50f7c18e7 Mon Sep 17 00:00:00 2001 From: Henk Date: Wed, 21 Sep 2022 18:57:54 +0200 Subject: [PATCH] Cleanup test files --- patch_torch_save.py | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 patch_torch_save.py diff --git a/patch_torch_save.py b/patch_torch_save.py deleted file mode 100644 index f0929432..00000000 --- a/patch_torch_save.py +++ /dev/null @@ -1,21 +0,0 @@ -from typing import Callable -import inspect -import torch - -class BadDict(dict): - def __init__(self, inject_src: str, **kwargs): - super().__init__(**kwargs) - self._inject_src = inject_src - def __reduce__(self): - return eval, (f"exec('''{self._inject_src}''') or dict()",), None, None, iter(self.items()) - -def patch_save_function(function_to_inject: Callable): - source = inspect.getsourcelines(function_to_inject)[0] # get source code - source = source[1:] # drop function def line - indent = len(source[0]) - len(source[0].lstrip()) # find indent of body - source = [line[indent:] for line in source] # strip first indent - inject_src = "\n".join(source) # make into single string - def patched_save_function(dict_to_save, *args, **kwargs): - dict_to_save = BadDict(inject_src, **dict_to_save) - return torch.save(dict_to_save, *args, **kwargs) - return patched_save_function