Skip to content

Commit

Permalink
attempt to work around weird dubious ownership thing
Browse files Browse the repository at this point in the history
  • Loading branch information
dlwh committed Feb 14, 2024
1 parent 7cf1686 commit 9fcb6f3
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/levanter/tracker/wandb.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,29 @@ def _git_settings(self):
other_settings["code_dir"] = code_dir
other_settings["git_root"] = code_dir
# for some reason, wandb isn't populating the git commit, so we do it here
try:
repo = Repo(code_dir)
other_settings["git_commit"] = repo.head.commit.hexsha
except (NoSuchPathError, InvalidGitRepositoryError):
logger.warning(f"Could not find git repo at {code_dir}")
pass
other_settings["git_commit"] = self._get_git_sha(code_dir)

return other_settings

def _get_git_sha(self, code_dir) -> Optional[str]:
try:
repo = Repo(code_dir)
git_sha = repo.head.commit.hexsha
except (NoSuchPathError, InvalidGitRepositoryError):
logger.warning(f"Could not find git repo at {code_dir}")
return None
except ValueError as e:
if "SHA is empty" in str(e):
# we have another workaround, which is to use the git command line
# git --git-dir={code_dir}/.git rev-parse HEAD
import subprocess

try:
out = subprocess.run(["git", "--git-dir", f"{code_dir}/.git", "rev-parse", "HEAD"], check=True)
git_sha = out.stdout.decode().strip()
except subprocess.CalledProcessError:
return None
else:
raise e

return git_sha

0 comments on commit 9fcb6f3

Please sign in to comment.