Skip to content

[Quantization] support pass MappingType for TorchAoConfig #10927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2025

Conversation

a120092009
Copy link
Contributor

@a120092009 a120092009 commented Feb 28, 2025

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 Feb 28, 2025
@a120092009 a120092009 force-pushed the fix-torchao-input-param branch from da327ef to 6621845 Compare February 28, 2025 07:50
@a120092009 a120092009 changed the title [Quantization] support pass MappingType for TorchAOConfig [Quantization] support pass MappingType for TorchAoConfig Feb 28, 2025
@a120092009 a120092009 force-pushed the fix-torchao-input-param branch 2 times, most recently from 6821dbe to 6b847cd Compare March 3, 2025 00:50
@a120092009
Copy link
Contributor Author

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

@a120092009 a120092009 force-pushed the fix-torchao-input-param branch from 6b847cd to ceb09f8 Compare March 3, 2025 01:14
@DN6 DN6 requested a review from a-r-r-o-w March 3, 2025 13:42
@a-r-r-o-w
Copy link
Member

@bot /style

Copy link
Contributor

github-actions bot commented Mar 4, 2025

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

Copy link
Member

@a-r-r-o-w a-r-r-o-w left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@a-r-r-o-w
Copy link
Member

The update test is passing for me locally, thanks!

@a-r-r-o-w a-r-r-o-w merged commit 11d8e3c into huggingface:main Mar 4, 2025
@a120092009 a120092009 deleted the fix-torchao-input-param branch March 5, 2025 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants