Skip to content

TOSA quant model memory usage regression #7896

Closed

Description

@hcindyl

person_detect model execution results in 30% more memory usage from [snapshot 697]{https://github.com/google/iree/releases/tag/snapshot-20211208.697} to [snapshot 709]{https://github.com/google/iree/releases/tag/snapshot-20211214.709}

memory stats @ 697

[INFO] [[ iree_hal_allocator_t memory statistics ]]
[INFO]   HOST_LOCAL:            0B peak /            0B allocated /            0B freed /            0B live
[INFO] DEVICE_LOCAL:        93730B peak /        93730B allocated /        93730B freed /            0B live

memory stats @ 709

[INFO] [[ iree_hal_allocator_t memory statistics ]]
[INFO]   HOST_LOCAL:            0B peak /            0B allocated /            0B freed /            0B live
[INFO] DEVICE_LOCAL:       121602B peak /       121602B allocated /       121602B freed /            0B live

Note that TOSA quant flow was broken in between those two snapshots.

The generated mlir out of iree-import-tflite is also 2kB more for snapshot 709
person_detect_mlir.tar.gz

The regression also happens in other quant models, such as mobilenetV1; but floating version of mobilenetV1 is not affected.

Activity

  1. added
    bug 🐞
    integrations/tosa
    on Dec 16, 2021
  2. hcindyl commented on Jan 11, 2022

    @hcindyl
    ContributorAuthor

    Since snapshot 731, the hal memory for this model further grows to 241kB

    [INFO] [[ iree_hal_allocator_t memory statistics ]]
    [INFO]   HOST_LOCAL:            0B peak /            0B allocated /            0B freed /            0B live
    [INFO] DEVICE_LOCAL:       241186B peak /       241186B allocated /       241186B freed /            0B live
    
  3. rsuderman commented on Jan 11, 2022

    @rsuderman
    Collaborator

    So the optional decomposition was removed during this period of time. It would be useful to have a method to test the memory changes. It is possible the decomposition was benefiting and these regressions are unrelated to TOSA/TFLite specific work.

  4. linked a pull request that will close this issueUse default TosaToLinalg passes #8161on Jan 21, 2022
  5. rsuderman commented on Jan 22, 2022

    @rsuderman
    Collaborator

    Reopened until we can validate

  6. rsuderman commented on Jan 27, 2022

    @rsuderman
    Collaborator

    Validated that its in. Assigning back to @hcindyl to validate whether memory usage is reasonable.

  7. benvanik commented on Jan 27, 2022

    @benvanik
    Collaborator

    the new -iree-scheduling-dump-statistics-format=pretty flag can be used on iree-translate to see the transient memory usage (for these simple static models) - may be useful for these kind of things as no need to run

  8. hcindyl commented on Jan 27, 2022

    @hcindyl
    ContributorAuthor

    Awesome! I thought we couldn't discover the runtime hal buffer usage in the codegen time. It would be fantastic to know ahead of time to see if we blow heap or not.

  9. benvanik commented on Jan 27, 2022

    @benvanik
    Collaborator

    It's a different number than what the runtime can give - the runtime gives you the peak memory usage while the compiler can only give you an estimated cumulative sum of transients that could be allocated, so if you had this:

    if (cond) { run_model_subgraph_a(alloca(1000)); }
    else { run_model_subgraph_b(alloca(3000)); }
    

    The runtime would give you 1000 or 3000 depending on cond while the compiler stats will give you 4000 (1000+3000). Loops and other things will make it skew even further.

    It can be useful, though, for relative comparisons: so something like "the cumsum of the transient allocations at revision T was 4000 and at revision T+1 was 6000, so we are probably allocating more memory in some cases" - it may not even change the peak consumption at runtime but does indicate that we have more live transients in the program (what all of these regressions have been).

    We could refine the statistic in some cases but it's a halting problem situation: at the point that we have to effectively run the program within the compiler it's better just to run the program, and having a robust number that won't break if an if or for shows up in the model is nice.

    TLDR: it'll let you compare transient memory growth revision to revision but to get the actual memory consumption you'll need to still run the model. Should still be a useful signal, though, and something we could track on a dashboard (so long as we didn't put units next to it and claim it was the actual memory consumption :)

  10. jpienaar commented on Jul 1, 2022

    @jpienaar
    Member

    Was this triaged? Still issue?

  11. hcindyl commented on Jul 1, 2022

    @hcindyl
    ContributorAuthor

    There are major compiler and runtime changes since January. With the latest release candidate-20220630.189

    [[ iree_hal_allocator_t memory statistics ]]
      HOST_LOCAL:         9216B peak /         9216B allocated /         9216B freed /            0B live
    DEVICE_LOCAL:       141570B peak /       141570B allocated /       141570B freed /            0B live
    

    We can close this issue for now. There are extra efforts to track the memory usage in the benchmark framework (#7972) so hopefully we can catch the regression sooner once it is landed.

  12. jpienaar commented on Jul 1, 2022

    @jpienaar
    Member

    Great, thanks

  13. moved this to Done in IREEon Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug 🐞integrations/tosa

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions