Skip to content

Commit

Permalink
auto test and doc (#19)
Browse files Browse the repository at this point in the history
* auto test and doc

* black

* update workflow

* inst

* dep in workflow

* updates

* a bit instr

---------

Co-authored-by: Ruilong Li <[email protected]>
  • Loading branch information
liruilong940607 and Ruilong Li authored Sep 29, 2023
1 parent 20b6e44 commit 93501bb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/core_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ jobs:
python-version: "3.8.12"
- name: Install dependencies
run: |
pip install black[jupyter]==22.3.0
pip install black[jupyter]==22.3.0 pytest
pip install torch==2.0.0 --index-url https://download.pytorch.org/whl/cpu
BUILD_NO_CUDA=1 pip install .
- name: Run Black Format Check
run: black . diff_rast/ tests/ examples/ --check
- name: Run Tests.
run: pytest tests/
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

Our version of differentiable gaussian rasterizer

# Installation
## Installation

Clone the repository and submodules with

```
```bash
git clone --recurse-submodules URL
```

Expand All @@ -15,31 +16,44 @@ first run. The benefit of JIT compiling is that it does incremental compiling as
you modify your cuda code so it is much faster than re-compile through pip. Note
the JIT compiled library can be found under `~/.cache/torch_extensions/py*-cu*/`.

```
```bash
BUILD_NO_CUDA=1 pip install -e .[dev]
```

If you won't touch the underlying CUDA code, you can just install with compiling:

```
```bash
pip install -e .[dev]
```

# Development
## Development

## Protect Main Branch over Pull Request.
It is recommend to commit the code into the main branch as a PR over a hard push, as the
PR would protect the main branch if the code break tests but a hard push won't.

It is recommended to commit the code into the main branch as a PR over a hard push, as the PR would protect the main branch if the code break tests but a hard push won't. Also squash the commits before merging the PR so it won't span the git history.

The curret tests that will be triggered by PR:
- `.github/workflows/core_tests.yml`: Black formating.

- `.github/workflows/core_tests.yml`: Black formating. Pytests.
- `.github/workflows/doc.yml`: Doc build.

Because we check for black formatting, it is recommend to run black before commit in the code:

```bash
black . diff_rast/ tests/ examples/
```
black . diff_rast/ tests/ examples/ --check

Since there is no GPU supported on github workflow container, we test against those cuda unit tests under `tests/`. So it is recommended to check test pass locally before committing:

```bash
pytest tests/ # check for all tests
pytest tests/test_cov2d_bounds.py # check for a single test file.
```

Note that `pytest` recognizes and runs all functions named as `test_*`, so you should name the
test functions in this pattern. See `test_cov2d_bounds.py` as an example.


## Build the Doc Locally
If you want to contribute to the doc, here is the way to build it locally. The source code of the doc can be found in `docs/source` and the built doc will be in `_build/`. Here are some examples on documentation: [viser](https://github.com/nerfstudio-project/viser/tree/main/docs/source), [nerfstudio](https://github.com/nerfstudio-project/nerfstudio/tree/main/docs), [nerfacc](https://github.com/KAIR-BAIR/nerfacc/tree/master/docs/source).

Expand Down
5 changes: 4 additions & 1 deletion diff_rast/_torch_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def eval_sh_bases(basis_dim: int, dirs: torch.Tensor):

def quat_to_rotmat(quat: Tensor) -> Tensor:
assert quat.shape[-1] == 4, quat.shape
x, y, z, w = torch.unbind(F.normalize(quat, dim=-1), dim=-1)
w, x, y, z = torch.unbind(F.normalize(quat, dim=-1), dim=-1)
return torch.stack(
[
torch.stack(
Expand Down Expand Up @@ -163,6 +163,9 @@ def project_cov3d_ewa(
W = viewmat[..., :3, :3] # (..., 3, 3)
p = viewmat[..., :3, 3] # (..., 3)
t = torch.matmul(W, mean3d[..., None])[..., 0] + p # (..., 3)
raise NotImplementedError(
"Need to incorporate changes from this commit: 85e76e1c8b8e102145922f561800a74262ceb196!"
)
rz = 1.0 / t[..., 2] # (...,)
rz2 = rz**2 # (...,)
J = torch.stack(
Expand Down
12 changes: 6 additions & 6 deletions tests/test_cov2d_bounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
device = torch.device("cuda:0")


@pytest.mark.skipif(not torch.cuda.is_available, reason="No CUDA device")
def compare_binding_to_pytorch():
@pytest.mark.skipif(not torch.cuda.is_available(), reason="No CUDA device")
def test_compare_binding_to_pytorch():
from diff_rast._torch_impl import compute_cov2d_bounds as _compute_cov2d_bounds
from diff_rast.cov2d_bounds import compute_cov2d_bounds

Expand All @@ -27,13 +27,13 @@ def compare_binding_to_pytorch():
)

conic, radii = compute_cov2d_bounds.apply(covs2d)
_conic, _radii, _ = _compute_cov2d_bounds(_covs2d)
_conic, _radii, _mask = _compute_cov2d_bounds(_covs2d)

radii = radii.squeeze(-1)

torch.testing.assert_close(conic, _conic)
torch.testing.assert_close(radii, _radii)
torch.testing.assert_close(conic[_mask], _conic[_mask])
torch.testing.assert_close(radii[_mask], _radii[_mask])


if __name__ == "__main__":
compare_binding_to_pytorch()
test_compare_binding_to_pytorch()

0 comments on commit 93501bb

Please sign in to comment.