Skip to content

MET-34 Blender - #18

Merged
arijit-dasgupta merged 7 commits into
masterfrom
arijit/MET-34-blender
Nov 29, 2025
Merged

MET-34 Blender#18
arijit-dasgupta merged 7 commits into
masterfrom
arijit/MET-34-blender

Conversation

@arijit-dasgupta

Copy link
Copy Markdown
Contributor

I have implemented two types of blender:

  1. Three parameter blender
  2. Four parameter blender

I have also added kwargs support for the get_confidence method for the confidence bindings (minor QOL change)

I have also removed the ray and fmb args from forward.cu, for they are not needed. All we need is the t_i and d_i.

NOTE: I have not implemented zero parameter blending. That one requires sorting all FMBs for every pixel, whic does not fit into our structure in forward.cu currently. I suggest we get to it if we want to (will triage it).

@linear

linear Bot commented Nov 22, 2025

Copy link
Copy Markdown
MET-34 Implement `Blender`

Definition of done

  • unit tests for different blenders compared to equations in the FMB++ pass

Comment thread genmetaballs/src/cuda/bindings.cu Outdated
Comment on lines +38 to +39
.def_rw("beta4", &TwoParameterConfidence::beta4)
.def_rw("beta5", &TwoParameterConfidence::beta5)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to use def_ro for immutable types.

Comment thread genmetaballs/src/cuda/bindings.cu Outdated
.def(nb::init<float, float, float>())
.def_rw("beta1", &ThreeParameterBlender::beta1)
.def_rw("beta2", &ThreeParameterBlender::beta2)
.def_rw("eta", &ThreeParameterBlender::eta)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't do shit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also def_ro

float eta;

CUDA_CALLABLE __forceinline__ float blend(float t, float d) const {
return expf((beta1 * d * sigmoid((beta3 / eta) * t)) - ((beta2 / eta) * t));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

"TwoParameterConfidence",
"sigmoid",
"FourParameterBlender",
"ThreeParameterBlender",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of directly exposing the confidence methods, let's have a .blender

@horizon-blue horizon-blue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly LGTM except some minor nitpicking :). Feel free to merge then you're ready.

One thing I started to realize for AI-generated tests is that while the are very comprehensive, they can be quite distracting as well. As a reviewer, I often ended up spending the majority of my reviewing cycles trying to decipher what we are trying to do.

Aside from testing for correctness, unit tests are often very useful in conveying intention of designs, e.g. I see that @mugamma's FMB PR has a test on range-based for loop, so I can immediately tell why he's writing the iterators earlier. This is not a huge issue here since this PR is mostly about math, though it'd be great if we can have more human readable tests :).

float beta3;
float eta;

CUDA_CALLABLE __forceinline__ float blend(float t, float d) const {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be nice to have definition of the methods in a blender.cu file :)

Comment on lines +31 to +37
std::vector<float> result(n);

CUDA_CHECK(cudaMalloc(&d_t, nbytes));
CUDA_CHECK(cudaMalloc(&d_d, nbytes));
CUDA_CHECK(cudaMalloc(&d_blended, nbytes));
CUDA_CHECK(cudaMemcpy(d_t, t_vec.data(), nbytes, cudaMemcpyHostToDevice));
CUDA_CHECK(cudaMemcpy(d_d, d_vec.data(), nbytes, cudaMemcpyHostToDevice));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability: you might want to look into some of thrust's utilities (e.g. thrust::device_vector) to reduce the amount of manual memory management :).

Comment thread tests/python_tests/test_blender.py Outdated
Comment on lines +61 to +63
def create_blender_instance(kwargs: dict) -> FourParameterBlender:
"""Helper to instantiate FourParameterBlender with the provided parameters."""
return FourParameterBlender(kwargs["beta1"], kwargs["beta2"], kwargs["beta3"], kwargs["eta"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is just a single line & this function is only used in one place, how about moving this inline?

# Check for finiteness (blend can in rare cases produce 0 or inf for extreme values)
assert np.isfinite(actual)

# INSERT_YOUR_CODE

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just helps to make sure that the exp does not blow up, it was happening with some large param values

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I was referring to this random # INSERT_YOUR_CODE comment lol

Comment on lines +69 to +70
@pytest.mark.parametrize("blender_kwargs", BLENDER_TEST_CASES)
def test_blender_single_value(rng_seed: int, blender_kwargs: dict) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW: Pytest actually support parametrizing over multiple arguments. You might find this helpful if you want avoid carrying around a kwargs dict (I'm personally fine with leaving this here).

@arijit-dasgupta
arijit-dasgupta merged commit d57cc5c into master Nov 29, 2025
1 check passed
@arijit-dasgupta
arijit-dasgupta deleted the arijit/MET-34-blender branch November 29, 2025 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants