iree-org / iree

A retargetable MLIR-based machine learning compiler and runtime toolkit.
http://iree.dev/
Apache License 2.0
2.78k stars 602 forks source link

Python bindings silently accept f64 scalars and return garbage when the module accepts f32 #12967

Open sogartar opened 1 year ago

sogartar commented 1 year ago

What happened?

I have a module function that accepts a f32 scalar. When I call it with

my_module.f(1.0)

I get garbage.

Same thing happens if I call it with int.

my_module.f(1)

It should either raise an error or do the correct conversion.

Steps to reproduce your issue

  1. Compile this MLIR

    func.func @f(%arg0: f32) -> f32 {
    %0 = math.exp2 %arg0 : f32
    return %0 : f32
    }

    with

    iree-compile --iree-hal-target-backends=llvm-cpu -o f.vmfb f.mlir
  2. Load into the module

    import iree.runtime
    vm_module = iree.runtime.load_vm_flatbuffer_file("f.vmfb", backend="local-task")
  3. Run the function

    vm_module.f(2.0)

This returns 1.0 when it should return 4.0.

What component(s) does this issue relate to?

Python

Version information

On top of d1ae167ad685e068f55a736e2e0861e324175313.

Additional context

No response

allieculp commented 1 year ago

@jpienaar @stellaraccident Another issue here regarding python bindings - let me know if we have a resource!

aaron-schneider commented 1 year ago

Added Jacques to find an owner.

jpienaar commented 1 year ago

@sgerrard could you perhaps see if you could see if we could flag this as an error instead?

sgerrard commented 1 year ago

Yes, I will take a look at this.