Repository: EleutherAI/lm-evaluation-harness
Issue: [Bug] `add_env_info` causes error when not running from base directory
Root cause: Validation Gap

This PR added this functionality `add_env_info`: https://github.com/EleutherAI/lm-evaluation-harness/commit/f78e2da45f034a23b1b13cde3235105b0f55d830

In my use case, I was running the eval from within a subfolder, `lm-evaluation-harness/eval` in a checked out commit. This led to the following error:
```bash
Traceback (most recent call last):
  File "/usr/bin/lm_eval", line 8, in <module>
    sys.exit(cli_evaluate())
  File "/lm-evaluation-harness/lm_eval/__main__.py", line 318, in cli_evaluate
    results = evaluator.simple_evaluate(
  File "/lm-evaluation-harness/lm_eval/utils.py", line 288, in _wrapper
    return fn(*args, **kwargs)
  File "/lm-evaluation-harness/lm_eval/evaluator.py", line 265, in simple_evaluate
    add_env_info(results)  # additional environment info to results
  File "/lm-evaluation-harness/lm_eval/logging_utils.py", line 441, in add_env_info
    upper_dir_commit = get_commit_from_path(
  File "/lm-evaluation-harness/lm_eval/logging_utils.py", line 415, in get_commit_from_path
    git_hash = head_ref.read_text(encoding="utf-8").replace("\n", "")
  File "/usr/lib/python3.10/pathlib.py", line 1134, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
  File "/usr/lib/python3.10/pathlib.py", line 1119, in open
    return self._accessor.open(self, mode, buffering, encoding, errors,
FileNotFoundError: [Errno 2] No such file or directory: '/lm-evaluation-harness/eval/../.git/8051d954e68ba3156beda9af72f2192772a2e7ab'
```

This is due to this code not handling exceptions:
```py
    upper_dir_commit = get_commit_from_path(
         Path(os.getcwd(), "..")
     )  # git hash of upper repo if exists
```

Note: running from base directory `/lm-evaluation-harness/` works fine.

> This is due to this code not handling exceptions

Since you know the solution, can you please do a PR with it?

I believe the root cause of the issue is related to being in a detached head which is the case when you checkout a specific version.  When you are in a detached head the HEAD file contains a hash instead of the path expected by the function.   This means that the path constructed on line 414 doesn't exist.

https://github.com/EleutherAI/lm-evaluation-harness/blob/34c9b7e40825ec998e44c5f45041953249c06a7b/lm_eval/logging_utils.py#L414
 
If your head is not detached (i.e. if you didn't checkout a specific revision) then the HEAD file contains a path that the function can use.

(Feature request: even if the detached issue is not fixed can the code that tries to infer git hashes fail more gracefully i.e. catch all exceptions and simply return None if it fails?)

>catch all exceptions and simply return None if it fails

Why is this solution better than directly check if `head_ref` exists (if the problem is really in `head_ref`)?
```python
if head_ref.exists():
    git_hash = head_ref.read_text(encoding="utf-8").replace("\n", "")
else:
    git_hash = None
```

> > catch all exceptions and simply return None if it fails
> 
> Why is this solution better than directly check if `head_ref` exists (if the problem is really in `head_ref`)?
> 
> ```python
> if head_ref.exists():
>     git_hash = head_ref.read_text(encoding="utf-8").replace("\n", "")
> else:
>     git_hash = None
> ```

Yeah this works for me. I guess I was saying catch all exceptions because I am worried that there may be other failure modes and the uncaught exception kills our runs.