LAP-DEV commited on
Commit
5b573eb
·
verified ·
1 Parent(s): 4adf2ca

Update modules/translation/translation_base.py

Browse files
modules/translation/translation_base.py CHANGED
@@ -185,7 +185,16 @@ class TranslationBase(ABC):
185
  raise
186
  finally:
187
  self.release_cuda_memory()
188
-
 
 
 
 
 
 
 
 
 
189
  @staticmethod
190
  def get_device():
191
  if torch.cuda.is_available():
 
185
  raise
186
  finally:
187
  self.release_cuda_memory()
188
+
189
+ def offload(self):
190
+ """Offload the model and free up the memory"""
191
+ if self.model is not None:
192
+ del self.model
193
+ self.model = None
194
+ if self.device == "cuda":
195
+ self.release_cuda_memory()
196
+ gc.collect()
197
+
198
  @staticmethod
199
  def get_device():
200
  if torch.cuda.is_available():