mitsuba-renderer / mitsuba3

Mitsuba 3: A Retargetable Forward and Inverse Renderer
https://www.mitsuba-renderer.org/
Other
2.05k stars 240 forks source link

Autodiff Run Time Error #791

Open zichenwang01 opened 1 year ago

zichenwang01 commented 1 year ago

Summary

Hi,

I developed a custom sphere tracer and wanted to forward a single parameter to the rendered image.

    dr.set_grad(p, 1)
    dr.forward_to(image)

The custom integrator works fine for normal rendering. However, weird things happened that when I forward a single parameter, I have to have an irrelevant line L_np = np.array(L) or otherwise the program halts without any error message.

    L = L * ray_weight
    # L_np = np.array(L)

    # put RGB values in the film
    block : mi.ImageBlock = sensor.film().create_block()
    RGB = [None] * 3
    RGB[0] = L.x
    RGB[1] = L.y
    RGB[2] = L.z
    if block.channel_count() == 4: # alpha channel
        RGB.append(mi.Float(1)) 
    block.put(position_sample, RGB, active)
    gc.collect() # collect garbage
    sensor.film().put_block(block)

    # develop the film to get the image        
    return sensor.film().develop() 

System configuration

System information:

OS: Windows11 CPU: Intel i5 GPU: None Python version: 3.11.3 LLVM version: 15.0.6 CUDA version: None NVidia driver: ...

Dr.Jit version: 0.4.2 Mitsuba version: 3.3.0 Compiled with: ... Variants compiled: ...

Description

Steps to reproduce

  1. ...
  2. ...
njroussel commented 1 year ago

Hi @zichenwang01

This most likely is due to a bug in Dr.Jit. Explicit evaluations, like the additional numpy conversion, should never be needed. I would recommend building the project from source, the current master branch has quite a few bug fixes.

Unfortunately, without a reproducer I can't really provide more help.

merlinND commented 1 year ago

Hello @zichenwang01,

the program halts without any error message

Does your code import pytorch or tensorflow as well? I'm asking because this behavior might be caused by an exception thrown inside of DrJit or Mitsuba. The exception could be legitimate, but the code that handles that exception in the C++ runtime loaded from another module could be incompatible, causing a segfault or weird silent crash. I've encountered this issue when importing PyTorch and Mitsuba in the same script on Linux, where one was compiled with libc++ and the other with libstdc++.

zichenwang01 commented 1 year ago

Hello @zichenwang01,

the program halts without any error message

Does your code import pytorch or tensorflow as well? I'm asking because this behavior might be caused by an exception thrown inside of DrJit or Mitsuba. The exception could be legitimate, but the code that handles that exception in the C++ runtime loaded from another module could be incompatible, causing a segfault or weird silent crash. I've encountered this issue when importing PyTorch and Mitsuba in the same script on Linux, where one was compiled with libc++ and the other with libstdc++.

No, it does not import pytorch or tensorflow. But I will keep a note of that in the future. Thanks!

njroussel commented 1 year ago

I'm unfamiliar with Window's logging system. But typically, a drjit error will intentionally crash the process it's running in with a error message. I'm assuming that this is what is happening in your setup but you simply can't see this error message. Jupyter is particularly awful at capturing these logs. If you're using a notebook, you might want to convert it to a simple Python script and execute it normally. Hopefully that will be a bit more verbose.