Beispiel #1
0
 def save(self, output_dir: Union[Path, str]) -> bool:
     full_dir = Path(output_dir) / instance_full_classname(
         self) / instance_full_classname(self.model)
     logger.info(f"Saving HuggingFace model to {full_dir}")
     os.makedirs(full_dir, exist_ok=True)
     self.model.save_pretrained(full_dir)
     return True
Beispiel #2
0
 def save(self, output_dir: Union[Path, str]) -> bool:
     full_dir = Path(output_dir) / instance_full_classname(self)
     logger.debug(f"Saving {instance_full_classname(self)} & AdamW optimizer to {full_dir}")
     os.makedirs(full_dir, exist_ok=True)
     self.model.save(full_dir)
     torch.save(self.optimizer.state_dict(), full_dir / "adamw_state_dict.pth")
     return True
Beispiel #3
0
 def save(self, output_dir: Union[Path, str]) -> bool:
     full_dir = Path(output_dir) / instance_full_classname(self)
     logger.debug(
         f"Saving {instance_full_classname(self)} instance to {full_dir}")
     os.makedirs(full_dir, exist_ok=True)
     # torch.save(self.state_dict(), full_dir / "state_dict.pth")
     torch.save(self, full_dir / "model.bin")
     return True
Beispiel #4
0
 def save(self, output_dir: Union[Path, str]) -> bool:
     d = Path(output_dir) / instance_full_classname(self)
     if not os.path.exists(d):
         os.makedirs(d)
     logger.info(f"Saving Config to {d / 'config.conf'}")
     with open(d / "config.conf", "w") as f:
         f.write(HOCONConverter.to_hocon(self.config))
     return True
Beispiel #5
0
 def save(self, output_dir: Union[Path, str]) -> bool:
     d = Path(output_dir) / instance_full_classname(self)
     records: MutableMapping[str, Recordable] = {
         "query_encoder": self.query_encoder,
         "code_encoder": self.code_encoder,
     }
     if self.pooler is not None:
         records["pooler"] = self.pooler
     return save_recordable_mapping(output_dir=d, records=records)
Beispiel #6
0
    def save(self, output_dir: Union[Path, str]) -> bool:
        fp = Path(self.conf_file)
        d = Path(output_dir) / instance_full_classname(self)
        if not os.path.exists(d):
            os.makedirs(d)
        logger.info(f"Saving Config File {self.conf_file} to {d}")

        shutil.copyfile(fp, d / fp.name)
        return True
Beispiel #7
0
    def save(self, output_dir: Union[Path, str]) -> bool:
        d = Path(output_dir) / instance_full_classname(self)
        if not os.path.exists(d):
            os.makedirs(d)
        logger.info(f"Saving State dict to {d}")

        # js = json.dumps(self.state)
        js = json.dumps(self)
        f = open(d / "state_dict.json", "w")
        f.write(js)
        f.close()
        # pickle.dump(self.state, open(d / "state_dict.txt", "w"))
        return True
Beispiel #8
0
 def save(self, output_dir: Union[Path, str]) -> bool:
     d = Path(output_dir) / instance_full_classname(self)
     for name, record in self.records.items():
         record.save(d / name)
     return True
Beispiel #9
0
 def save(self, output_dir: Union[Path, str]) -> bool:
     d = Path(output_dir) / instance_full_classname(self)
     for name, record in self.items():
         logger.debug(f"RecordableMapping - Saving {name}")
         record.save(d / name)
     return True