Skip to content
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

#17312: Fix type error when saving report config to json file #17350

Merged
merged 1 commit into from
Jan 30, 2025

Conversation

smountenay-tt
Copy link
Contributor

Ticket

#17312

Problem description

Running pytest with the TTNN_CONFIG_OVERRIDES environment variable set to enable detailed buffer reports will fail with TypeError: Object of type method is not JSON serializable if a config.json file does not already exist in the report directory.

Debugging the issue with pdb I determined that the cause of the problem was due to an unexpected _pybind11_conduit_v1_ key in the normalized_config dict that is written to the config.json file in the ttnn.save_config_to_json_file function.

There was logic in this function already to ignore dunder methods and attributes from the original CONFIG object, but the if "__" in key: check that matched regular Python special attributes didn't match the _pybind11_conduit_v1_ attribute returned by dir(CONFIG).

I experienced this issue personally every time I deleted the reports directory, which I was doing frequently to ensure that each report only had data from a single run.

Oddly, it would only fail on the first run after deleting the reports directory, and on subsequent runs of pytest it would work and write the config.json file fine. This leads me to believe that this _pybind11_conduit_v1_ property did not always exist on the CONFIG object, but understanding why was outside the scope of my debugging to unblock me.

The issue was also reported to us by another user.

What's changed

I have changed the logic in ttnn.save_config_to_json_file so that instead of ignoring any config attributes with __ in their name, it instead ignores any config attributes that start and end with an underscore. This preserves the original intention of ignoring the standard Python special attributes, but also any other pseudo-special attributes like this one.

This solution generalizes things a bit, without explicitly excluding the _pybind11_conduit_v1_ attribute. Alternatively, we could be explicit about it by changing it to:

if "__" in key or key == "_pybind11_conduit_v1_":
    continue

I preferred the regex approach and think there's no performance implication since it's just writing a small config object once when a new report is created.

Checklist

  • Post commit CI passes
  • Blackhole Post commit (if applicable)
  • Model regression CI testing passes (if applicable)
  • Device performance regression CI testing passes (if applicable)
  • (For models and ops writers) Full new models tests passes
  • New/Existing tests provide coverage for changes

@smountenay-tt smountenay-tt merged commit 20360c5 into main Jan 30, 2025
10 of 11 checks passed
@smountenay-tt smountenay-tt deleted the smountenay-tt/17312-report_config_typeerror branch January 30, 2025 18:30
yieldthought pushed a commit that referenced this pull request Jan 31, 2025
### Ticket
[#17312](#17312)

### Problem description

Running pytest with the `TTNN_CONFIG_OVERRIDES` environment variable set
to enable detailed buffer reports will fail with `TypeError: Object of
type method is not JSON serializable` if a `config.json` file does not
already exist in the report directory.

Debugging the issue with pdb I determined that the cause of the problem
was due to an unexpected `_pybind11_conduit_v1_` key in the
`normalized_config` dict that is written to the `config.json` file in
the `ttnn.save_config_to_json_file` function.

There was logic in this function already to ignore dunder methods and
attributes from the original `CONFIG` object, but the `if "__" in key:`
check that matched regular Python special attributes didn't match the
`_pybind11_conduit_v1_` attribute returned by `dir(CONFIG)`.

I experienced this issue personally every time I deleted the reports
directory, which I was doing frequently to ensure that each report only
had data from a single run.

Oddly, it would only fail on the first run after deleting the reports
directory, and on subsequent runs of pytest it would work and write the
`config.json` file fine. This leads me to believe that this
`_pybind11_conduit_v1_` property did not always exist on the `CONFIG`
object, but understanding why was outside the scope of my debugging to
unblock me.

The issue was also reported to us by another user.

### What's changed

I have changed the logic in `ttnn.save_config_to_json_file` so that
instead of ignoring any config attributes with `__` in their name, it
instead ignores any config attributes that start and end with an
underscore. This preserves the original intention of ignoring the
standard Python special attributes, but also any other pseudo-special
attributes like this one.

This solution generalizes things a bit, without explicitly excluding the
`_pybind11_conduit_v1_` attribute. Alternatively, we could be explicit
about it by changing it to:

```
if "__" in key or key == "_pybind11_conduit_v1_":
    continue
```

I preferred the regex approach and think there's no performance
implication since it's just writing a small config object once when a
new report is created.

### Checklist
- [X] Post commit CI passes
- [ ] Blackhole Post commit (if applicable)
- [ ] Model regression CI testing passes (if applicable)
- [ ] Device performance regression CI testing passes (if applicable)
- [ ] **(For models and ops writers)** Full [new
models](https://github.com/tenstorrent/tt-metal/actions/workflows/full-new-models-suite.yaml)
tests passes
- [ ] New/Existing tests provide coverage for changes

Co-authored-by: Scott Mountenay <[email protected]>
nikileshx pushed a commit to nikileshx/tt-metal that referenced this pull request Feb 3, 2025
…ile (tenstorrent#17350)

### Ticket
[tenstorrent#17312](tenstorrent#17312)

### Problem description

Running pytest with the `TTNN_CONFIG_OVERRIDES` environment variable set
to enable detailed buffer reports will fail with `TypeError: Object of
type method is not JSON serializable` if a `config.json` file does not
already exist in the report directory.

Debugging the issue with pdb I determined that the cause of the problem
was due to an unexpected `_pybind11_conduit_v1_` key in the
`normalized_config` dict that is written to the `config.json` file in
the `ttnn.save_config_to_json_file` function.

There was logic in this function already to ignore dunder methods and
attributes from the original `CONFIG` object, but the `if "__" in key:`
check that matched regular Python special attributes didn't match the
`_pybind11_conduit_v1_` attribute returned by `dir(CONFIG)`.

I experienced this issue personally every time I deleted the reports
directory, which I was doing frequently to ensure that each report only
had data from a single run.

Oddly, it would only fail on the first run after deleting the reports
directory, and on subsequent runs of pytest it would work and write the
`config.json` file fine. This leads me to believe that this
`_pybind11_conduit_v1_` property did not always exist on the `CONFIG`
object, but understanding why was outside the scope of my debugging to
unblock me.

The issue was also reported to us by another user.

### What's changed

I have changed the logic in `ttnn.save_config_to_json_file` so that
instead of ignoring any config attributes with `__` in their name, it
instead ignores any config attributes that start and end with an
underscore. This preserves the original intention of ignoring the
standard Python special attributes, but also any other pseudo-special
attributes like this one.

This solution generalizes things a bit, without explicitly excluding the
`_pybind11_conduit_v1_` attribute. Alternatively, we could be explicit
about it by changing it to:

```
if "__" in key or key == "_pybind11_conduit_v1_":
    continue
```

I preferred the regex approach and think there's no performance
implication since it's just writing a small config object once when a
new report is created.

### Checklist
- [X] Post commit CI passes
- [ ] Blackhole Post commit (if applicable)
- [ ] Model regression CI testing passes (if applicable)
- [ ] Device performance regression CI testing passes (if applicable)
- [ ] **(For models and ops writers)** Full [new
models](https://github.com/tenstorrent/tt-metal/actions/workflows/full-new-models-suite.yaml)
tests passes
- [ ] New/Existing tests provide coverage for changes

Co-authored-by: Scott Mountenay <[email protected]>
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.

3 participants