Skip to content

Commit

Permalink
Remove incorrect early exit of Encoding::backward_impl
Browse files Browse the repository at this point in the history
When there are no outputs, backward_impl should produce a zero gradient
rather than not touching the gradient matrix at all.
  • Loading branch information
Tom94 committed Aug 5, 2023
1 parent 28ca991 commit 6f018a9
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/tiny-cuda-nn/encodings/empty.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class EmptyEncoding : public Encoding<T> {
bool use_inference_params = false,
GradientMode param_gradients_mode = GradientMode::Overwrite
) override {
if (!dL_dinput || padded_output_width() == 0) {
if (!dL_dinput) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion include/tiny-cuda-nn/encodings/frequency.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class FrequencyEncoding : public Encoding<T> {
bool use_inference_params = false,
GradientMode param_gradients_mode = GradientMode::Overwrite
) override {
if (!dL_dinput || padded_output_width() == 0) {
if (!dL_dinput) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion include/tiny-cuda-nn/encodings/grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ class GridEncodingTemplated : public GridEncoding<T> {
GradientMode param_gradients_mode = GradientMode::Overwrite
) override {
const uint32_t num_elements = input.n();
if ((!dL_dinput && param_gradients_mode == GradientMode::Ignore) || padded_output_width() == 0 || num_elements == 0) {
if ((!dL_dinput && param_gradients_mode == GradientMode::Ignore) || num_elements == 0) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion include/tiny-cuda-nn/encodings/identity.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class IdentityEncoding : public Encoding<T> {
bool use_inference_params = false,
GradientMode param_gradients_mode = GradientMode::Overwrite
) override {
if (!dL_dinput || padded_output_width() == 0) {
if (!dL_dinput) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion include/tiny-cuda-nn/encodings/oneblob.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class OneBlobEncoding : public Encoding<T> {
bool use_inference_params = false,
GradientMode param_gradients_mode = GradientMode::Overwrite
) override {
if (!dL_dinput || padded_output_width() == 0) {
if (!dL_dinput) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion include/tiny-cuda-nn/encodings/spherical_harmonics.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class SphericalHarmonicsEncoding : public Encoding<T> {
bool use_inference_params = false,
GradientMode param_gradients_mode = GradientMode::Overwrite
) override {
if (!dL_dinput || padded_output_width() == 0) {
if (!dL_dinput) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion include/tiny-cuda-nn/encodings/triangle_wave.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class TriangleWaveEncoding : public Encoding<T> {
bool use_inference_params = false,
GradientMode param_gradients_mode = GradientMode::Overwrite
) override {
if (!dL_dinput || padded_output_width() == 0) {
if (!dL_dinput) {
return;
}

Expand Down

0 comments on commit 6f018a9

Please sign in to comment.