forked from VSharp-team/VSharp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from emnigma/batching_in_common_model_training
Сохранение моделек и рефакторинг
- Loading branch information
Showing
5 changed files
with
118 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import os | ||
import pathlib | ||
|
||
csv_path = os.path.join("report", "epochs_tables") | ||
models_path = os.path.join("report", "epochs_best") | ||
common_models_path = os.path.join("report", "common_models") | ||
best_models_dict_path = os.path.join("report", "updated_best_models_dicts") | ||
dataset_root_path = os.path.join("report", "dataset") | ||
dataset_map_results_file_name = os.path.join("report", "dataset_state.csv") | ||
training_data_path = os.path.join("report", "run_tables") | ||
pretrained_models_path = os.path.join("ml", "models") | ||
CSV_PATH = os.path.join("report", "epochs_tables") | ||
MODELS_PATH = os.path.join("report", "epochs_best") | ||
COMMON_MODELS_PATH = os.path.join("report", "common_models") | ||
BEST_MODELS_DICT_PATH = os.path.join("report", "updated_best_models_dicts") | ||
DATASET_ROOT_PATH = os.path.join("report", "dataset") | ||
DATASET_MAP_RESULTS_FILENAME = os.path.join("report", "dataset_state.csv") | ||
TRAINING_DATA_PATH = os.path.join("report", "run_tables") | ||
PRETRAINED_MODEL_PATH = os.path.join("ml", "models") | ||
|
||
path_to_models_for_parallel_architecture = os.path.join( | ||
PATH_TO_MODELS_FOR_PARALLEL_ARCHITECTURE = os.path.join( | ||
"ml", "pretrained_models", "models_for_parallel_architecture" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import typing as t | ||
from datetime import datetime | ||
from pathlib import Path | ||
|
||
import torch | ||
from torch import Tensor | ||
|
||
|
||
class PathSelectorNNProtocol(t.Protocol): | ||
def forward( | ||
self, | ||
game_x, | ||
state_x, | ||
edge_index_v_v, | ||
edge_index_history_v_s, | ||
edge_attr_history_v_s, | ||
edge_index_in_v_s, | ||
edge_index_s_s, | ||
) -> Tensor: | ||
... | ||
|
||
|
||
def save_model(model: torch.nn.Module, /, **initargs): | ||
weights = model.state_dict() | ||
|
||
# ml.models.TAGSageSimple.model | ||
save_path_components = model.__module__.split(".")[:-1] | ||
|
||
# ml.models.TAGSageSimple.model.StateModelEncoder | ||
class_fullname = model.__module__ + "." + model.__class__.__name__ | ||
|
||
# **{hidden_channels: 32, out_channels: 8} | ||
model_initargs = "_".join([f"{param}_{value}" for param, value in initargs.items()]) | ||
|
||
save_dir = Path("/".join(save_path_components)) | ||
|
||
timestamp = datetime.fromtimestamp(datetime.now().timestamp()) | ||
|
||
suffix = ".pt" | ||
|
||
save_name = f"{class_fullname}{'_' + model_initargs + '_' if initargs else ''}{timestamp}{suffix}" | ||
|
||
torch.save(weights, save_dir / save_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters