Exemple #1
0
 def test_upgrade_to_latest(self):
     for p in glob.iglob(
             os.path.join(os.path.dirname(__file__), "json_config/*.json")):
         with open(p) as f:
             test_data = json.load(f)
             for test_case in test_data:
                 json_config = upgrade_to_latest(test_case["original"])
                 config_from_json(PyTextConfig, json_config)
Exemple #2
0
def load(load_path: str):
    """
    Load task, will construct the task using the saved config then load metadata
    and model state.
    """
    if not (load_path and os.path.isfile(load_path)):
        raise ValueError(f"Invalid snapshot path{load_path}")
    print(f"Loading model from {load_path}...")
    state = torch.load(load_path, map_location=lambda storage, loc: storage)
    config = config_from_json(PyTextConfig, state[CONFIG_JSON])
    task = create_task(config.task,
                       metadata=state[DATA_STATE],
                       model_state=state[MODEL_STATE])
    return task, config
 def _get_config(self, cls, config_str):
     params_json = json.loads(config_str)
     config = config_from_json(cls, params_json)
     return config