simple_context.py 978 B

1234567891011121314151617181920212223242526272829303132333435
  1. # This manages restoring and snapshotting the context.
  2. # The file is used in the BaseLLM class and the RRScheduler class.
  3. from aios.context.base import BaseContextManager
  4. import os
  5. import torch
  6. # import shutil
  7. class SimpleContextManager(BaseContextManager):
  8. def __init__(self):
  9. BaseContextManager.__init__(self)
  10. def start(self):
  11. pass
  12. def gen_snapshot(self, pid, context):
  13. file_path = os.path.join(self.context_dir, f"process-{pid}.pt")
  14. torch.save(context, file_path)
  15. def gen_recover(self, pid):
  16. file_path = os.path.join(self.context_dir, f"process-{pid}.pt")
  17. return torch.load(file_path)
  18. def check_restoration(self, pid):
  19. return os.path.exists(os.path.join(self.context_dir, f"process-{pid}.pt"))
  20. def clear_restoration(self, pid):
  21. # print(f"Process {pid} has been deleted.")
  22. os.remove(os.path.join(self.context_dir, f"process-{pid}.pt"))
  23. def stop(self):
  24. pass