Skip to content

Commit 56f02c4

Browse files
authored
[seq2seq]
It looks like gitpython is broken when one tries to use it from `git checkout hash`, see: gitpython-developers/GitPython#633 While debugging/bisecting we need to be able to step through different commits and for the code to still work. Currently it fails with: ``` ERR: File "./examples/seq2seq/distillation.py", line 504, in <module> ERR: distill_main(args) ERR: File "./examples/seq2seq/distillation.py", line 494, in distill_main ERR: model = create_module(args) ERR: File "./examples/seq2seq/distillation.py", line 411, in create_module ERR: model = module_cls(args) ERR: File "/mnt/nvme1/code/huggingface/transformers-multigpu/examples/seq2seq/finetune.py", line 58, in __init__ ERR: save_git_info(self.hparams.output_dir) ERR: File "/mnt/nvme1/code/huggingface/transformers-multigpu/examples/seq2seq/utils.py", line 355, in save_git_info ERR: repo_infos = get_git_info() ERR: File "/mnt/nvme1/code/huggingface/transformers-multigpu/examples/seq2seq/utils.py", line 374, in get_git_info ERR: "repo_branch": str(repo.active_branch), ERR: File "/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/git/repo/base.py", line 705, in active_branch ERR: return self.head.reference ERR: File "/home/stas/anaconda3/envs/main-38/lib/python3.8/site-packages/git/refs/symbolic.py", line 272, in _get_reference ERR: raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha)) ERR: TypeError: HEAD is a detached symbolic reference as it points to 'fb94b8f1e16eb21d166174f52e3e49e669ef0ac4' ``` This PR provides a workaround. @sshleifer
1 parent dfa4c26 commit 56f02c4

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

examples/seq2seq/utils.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -457,14 +457,23 @@ def load_json(path):
457457

458458

459459
def get_git_info():
460-
repo = git.Repo(search_parent_directories=True)
461-
repo_infos = {
462-
"repo_id": str(repo),
463-
"repo_sha": str(repo.head.object.hexsha),
464-
"repo_branch": str(repo.active_branch),
465-
"hostname": str(socket.gethostname()),
466-
}
467-
return repo_infos
460+
try:
461+
# XXX: workaround for https://github.com/gitpython-developers/GitPython/issues/633
462+
repo = git.Repo(search_parent_directories=True)
463+
repo_infos = {
464+
"repo_id": str(repo),
465+
"repo_sha": str(repo.head.object.hexsha),
466+
"repo_branch": str(repo.active_branch),
467+
"hostname": str(socket.gethostname()),
468+
}
469+
return repo_infos
470+
except (TypeError):
471+
return {
472+
"repo_id": None,
473+
"repo_sha": None,
474+
"repo_branch": None,
475+
"hostname": None,
476+
}
468477

469478

470479
ROUGE_KEYS = ["rouge1", "rouge2", "rougeL", "rougeLsum"]

0 commit comments

Comments
 (0)