Skip to content

[Flux] Empty output from the flux models #21019

Closed

Description

@pravg-amd

What happened?

When the flux models are compiled and executed, the generated output seems to be empty. This issue is visible from the commit d7bb36b

Steps to reproduce your issue

This can be reproduced using the steps in https://github.com/nod-ai/shark-ai/blob/e3beeed98eda98aaf88eabda282f8ba6985687a8/shortfin/python/shortfin_apps/flux/README.md?plain=1#L19

What component(s) does this issue relate to?

Compiler, Runtime

Version information

IREE commit: 4889cb5

Additional context

The issue occurs due to sharedMemBytes being set to 0 in the call to hipModuleLaunchKernel

d7bb36b#diff-faa5750ca692b9798a643f340a08b4bc22c7fedc5b304f4bb7d722e2df8209b8R581

Activity

  1. added
    bug 🐞
    on Jun 5, 2025
  2. MaheshRavishankar commented on Jun 5, 2025

    @MaheshRavishankar
    Collaborator

    It would be really helpful if you could give us the

    MLIR input
    IREE compile command
    Run command
    Input files and IRPA files to use.

  3. pravg-amd commented on Jun 5, 2025

    @pravg-amd
    ContributorAuthor

    @MaheshRavishankar @qedawkins I was not able to get a repro for IREE at this moment, but was able to identify that the issue is due to sharedMemBytes being set to 0 in the call to hipModuleLaunchKernel

    Will try to get the repo mlir/inputs to get the actual fix in,

    stream_command_buffer.c

    The sharedMemBytes contains the values when added a print before the call

    Image

  4. Muzammiluddin-Syed-ECE commented on Jun 11, 2025

    @Muzammiluddin-Syed-ECE
    Contributor

    There weren't significant changes in the IR beyond changes to the constant data: See gist

    After discussion with @AWoloszyn, the suggested solution is to reimplement support for the kernel_param block_shared_memory_size because there seems to be some kernel whose functionality unexpectedly depends on this param. Will provide udpate with which kernel specifically, soon.

  5. qedawkins commented on Jun 12, 2025

    @qedawkins
    Contributor

    If there is a kernel unexpectedly depending on that param, it might be stale. Unless there is a HIP quirk that makes specifying shared memory dynamically useful, we should avoid it. IOW the fix would be in the kernel still using the param, not to reimplement block_shared_memory_size.

    We can try undoing the revert, dropping the field from the revert, and recompiling the model to see if we get an error coming from whatever kernel is trying to use it.

  6. MaheshRavishankar commented on Jun 13, 2025

    @MaheshRavishankar
    Collaborator

    @pravg-amd we probably need help reproing properly. Codegen team has been having trouble actually reproing this. We need a better repro to be able to solve this issue faster.

  7. pravg-amd commented on Jun 16, 2025

    @pravg-amd
    ContributorAuthor

    @MaheshRavishankar Had a call with @Muzammiluddin-Syed-ECE to reproduce the error using shortfin.

    I was verifying compiling the above mlir files and running using the actual inputs with and without the reverted changes through iree-run-module. I do see correct outputs in both the cases.

    Looking at shortfin to find if the issue is indeed in shortfin's invocation of the iree apis. Will have a update on the root cause for this issue as soon as possible.

  8. qedawkins commented on Jun 16, 2025

    @qedawkins
    Contributor

    If you need a smoking gun, we can try my suggestion above (undo the revert and drop the field from the flatbuffer).

  9. pravg-amd commented on Jun 16, 2025

    @pravg-amd
    ContributorAuthor

    Removing the field block_shared_memory_size:uint32 (deprecated); from ~/iree/runtime/src/iree/schemas/hip_executable_def.fbs with revert being undone,

    It fails in shortfin with the following error

    ValueError: iree/runtime/src/iree/hal/drivers/hip/native_executable.c:109: INVALID_ARGUMENT; flatbuffer verification failed: vtable offset out of range or unaligned; while invoking native function hal.executable.create; while calling import;
    
  10. 4 remaining items

  11. pravg-amd commented on Jun 16, 2025

    @pravg-amd
    ContributorAuthor

    If it still happens after recompile, that means there is something stale (?). I would try printf debugging for the culprit here

    iree/runtime/src/iree/hal/drivers/hip/native_executable.c

    Line 109 in 1b0acbf

    return iree_make_status(IREE_STATUS_INVALID_ARGUMENT,
    (not sure what stuff will be printable)

    Thanks @qedawkins @MaheshRavishankar @benvanik for helping in tracking down the issue.

    The issue seems to be with the env setup being used for shortfin. When a pip package is installed and the shortfin is built using iree source locally, there seems to be some libraries which are not updated to make use of the updated sources.

    Printing the value of flatbuffer_data.data_length in native_executable.c helps in confirming the issue with shortfin.

    iree-run-module 
    
    Without revert - flatbuffer_data.data_length = 112212
    With revert - flatbuffer_data.data_length = 112868
    
    Shortfin
    
    With revert - flatbuffer_data.data_length = 112868
    Without revert - flatbuffer_data.data_length = 112868
    
  12. qedawkins commented on Jun 16, 2025

    @qedawkins
    Contributor

    Thanks for confirming the issue! In retrospect, deprecating the field the way that I did was likely not the right call with the implicated change as it meant pre-existing vmfbs could successfully load + run incorrectly because the block_shared_memory_size was no longer used.

    We can either drop the field entirely now, or keep it deprecated and continue passing it on dispatch and make sure the compiler never sets a non-zero value. That way old vmfbs will continue working as expected.

  13. benvanik commented on Jun 16, 2025

    @benvanik
    Collaborator

    We'll always need to keep the field until we make a breaking format change. Give it a release or two of always being 0 and then we can remove support and see if anyone notices. We don't make guarantees today that artifacts from one release will work with another (though one day we will).

  14. MaheshRavishankar commented on Jun 16, 2025

    @MaheshRavishankar
    Collaborator

    Oh.. wait I relanded the original change. We probably want to fix that @qedawkins to set the dynamic shared memory size to 0 always.

  15. qedawkins commented on Jun 16, 2025

    @qedawkins
    Contributor

    So anything generated + run with matching compiler and runtime versions will be consistent before and after the change. The issue is that a vmfb generated with differing versions will successfully run but produce invalid results. To enumerate the cases:

    On the compiler side:
    Before:
    We set blockSharedMemorySize to the amount of shared memory (and use no statically allocated shared memory)
    After:
    We never populate the field (so always defaults to 0)

    On the runtime side:
    Before:
    We use the block_shared_memory_size specified in the flatbuffer and pass that as the amount of shared memory on dispatch.
    After:
    We ignore the block_shared_memory_size field and always pass 0, regardless of what the deprecated flatbuffer field says. My reasoning at the time was that since we shouldn't ever be setting the deprecated field anyway, we don't want to ever accidentally double dip on memory requested.

    So that means if you took an old vmfb it would still load with the new runtime changes but wouldn't get any of the shared memory it asked for, which doesn't cause faults (IDT shared memory can fault), but instead just produces garbage (unallocated) values. A newly compiled vmfb would probably work with the previous runtime though.

  16. MaheshRavishankar commented on Jun 17, 2025

    @MaheshRavishankar
    Collaborator

    Ok, that makes it clear. Can we actually error out instead? I guess that would mean a version bump

  17. qedawkins commented on Jun 17, 2025

    @qedawkins
    Contributor

    I don't know what the procedure is for making a backend specific breaking format change. Do we have individual versioning per backend?

  18. benvanik commented on Jun 17, 2025

    @benvanik
    Collaborator

    Let's not break the format - keep it deprecated for now.

  19. benvanik commented on Jun 17, 2025

    @benvanik
    Collaborator

    (if you want to error on older files, then have the executable loader in the runtime code error out if the field is present and non-zero)

  20. qedawkins commented on Jun 17, 2025

    @qedawkins
    Contributor

    Aw, deprecating a field removed the getter

    __flatbuffers_define_scalar_field(0, iree_hal_hip_ExportDef, module_ordinal, flatbuffers_uint32, uint32_t, UINT32_C(0))
    __flatbuffers_define_string_field(1, iree_hal_hip_ExportDef, kernel_name, 0)
    __flatbuffers_define_struct_field(2, iree_hal_hip_ExportDef, block_dims, iree_hal_hip_BlockDims_struct_t, 0)
    /* Skipping deprecated field: 'iree_hal_hip_ExportDef_block_shared_memory_size' */
    
  21. benvanik commented on Jun 17, 2025

    @benvanik
    Collaborator

    aww, then probably have to keep it, do the check for a release, and then mark as deprecated.

  22. qedawkins commented on Jun 17, 2025

    @qedawkins
    Contributor

    #21118 adds the error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug 🐞

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions