diffusers
[Quantization] support pass MappingType for TorchAoConfig
#10927
Merged

[Quantization] support pass MappingType for TorchAoConfig #10927

a120092009
a120092009206 days ago (edited 203 days ago)

What does this PR do?

Passing MappingType for TorchAoConfig is invalid

  File "/workspace/volume/zty/diffusers/src/diffusers/configuration_utils.py", line 123, in register_to_config
    logger.debug(f"Updating config from {previous_dict} to {internal_dict}")
                                                           ^^^^^^^^^^^^^^^
  File "/workspace/volume/zty/diffusers/src/diffusers/quantizers/quantization_config.py", line 671, in __repr__
    return f"{self.__class__.__name__} {json.dumps(config_dict, indent=2, sort_keys=True)}\n"
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
          ^^^^^^^^^^^
  File "/usr/lib/python3.12/json/encoder.py", line 202, in encode
    chunks = list(chunks)
             ^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/encoder.py", line 432, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib/python3.12/json/encoder.py", line 406, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.12/json/encoder.py", line 406, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.12/json/encoder.py", line 439, in _iterencode
    o = _default(o)
        ^^^^^^^^^^^
  File "/usr/lib/python3.12/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type MappingType is not JSON serializable

Add JSON encoder for supporting MappingType

Test result:

image

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline?
  • Did you read our philosophy doc (important for complex PRs)?
  • Was this discussed/approved via a GitHub issue or the forum? Please add a link to it if that's the case. (Not related issue or PR yet)
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

a120092009 a120092009 changed the title fix(torchao): support pass MappingType [Quantization] support pass MappingType for TorchAOConfig 206 days ago
a120092009 a120092009 force pushed from da327ef8 to 66218459 206 days ago
a120092009 a120092009 changed the title [Quantization] support pass MappingType for TorchAOConfig [Quantization] support pass MappingType for TorchAoConfig 206 days ago
a120092009 a120092009 force pushed from 66218459 to 6821dbef 206 days ago
a120092009 a120092009 force pushed from 6821dbef to 6b847cd1 204 days ago
a120092009
a120092009204 days ago

@a-r-r-o-w @dacorvo Could you guys take a look, thx :)

a120092009 [Quantization] support pass MappingType for TorchAoConfig
ceb09f88
a120092009 a120092009 force pushed from 6b847cd1 to ceb09f88 204 days ago
DN6 DN6 requested a review from a-r-r-o-w a-r-r-o-w 203 days ago
a-r-r-o-w
a-r-r-o-w202 days ago

@bot /style

github-actions[bot] Apply style fixes
487f201e
github-actions
github-actions202 days ago

Style fixes have been applied. View the workflow run here.

a-r-r-o-w
a-r-r-o-w approved these changes on 2025-03-04
a-r-r-o-w202 days ago

Thank you!

a-r-r-o-w
a-r-r-o-w202 days ago

The update test is passing for me locally, thanks!

a-r-r-o-w a-r-r-o-w merged 11d8e3ce into main 202 days ago
a120092009 a120092009 deleted the fix-torchao-input-param branch 202 days ago

Login to write a write a comment.

Login via GitHub

Reviewers
Assignees
No one assigned
Labels
Milestone