Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Added for saving git info #5701

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added metric `FBetaVerboseMeasure` which extends `FBetaMeasure` to ensure compatibility with logging plugins and add some options.
- Added three sample weighting techniques to `ConditionalRandomField` by supplying three new subclasses: `ConditionalRandomFieldWeightEmission`, `ConditionalRandomFieldWeightTrans`, and `ConditionalRandomFieldWeightLannoy`.
- Added saving of github repo infos along with other metadata in model archives.

### Fixed

Expand Down
15 changes: 14 additions & 1 deletion allennlp/common/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from dataclasses import dataclass, asdict
import json
import logging
import git
import socket
from typing import Union

from allennlp.version import VERSION
Expand All @@ -28,10 +30,21 @@ def new(cls) -> "Meta":

def to_file(self, path: Union[PathLike, str]) -> None:
with open(path, "w") as meta_file:
json.dump(asdict(self), meta_file)
json.dump(asdict(self).update(get_git_info()), meta_file)

@classmethod
def from_path(cls, path: Union[PathLike, str]) -> "Meta":
with open(path) as meta_file:
data = json.load(meta_file)
return cls(**data)


def get_git_info():
repo = git.Repo(search_parent_directories=True)
repo_info = {
"repo_id": str(repo),
"repo_sha": str(repo.head.object.hexsha),
"repo_branch": str(repo.active_branch),
"hostname": str(socket.gethostname()),
}
return repo_info