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

[Fix] Fix dump method of Config #1837

Merged
merged 11 commits into from
May 10, 2022
Merged

Conversation

jmercat
Copy link

@jmercat jmercat commented Mar 26, 2022

Motivation:

When loading a config from a dict, the dump function does not work. Dump should not depend on how config was loaded but only where it is dumped.

Modification:

Changed checks for type in dump. It used to check the config source filename and I changed it to the destination filename. When there is no input file argument, it does not save the config in a file but returns a string. I am not sure this is the desired behavior but the format of this string depends on self.filename (format matching source format). I personally don’t think this is the best choice but I think this is the closest behavior to the previous version.

Use cases (Optional)

It would offer the ability for a config loaded from a dict to be dumped.

dump should not depend on how config was loaded only where it is dumped
changed checks for type to the given filename instead of the source filename
@mm-assistant mm-assistant bot added the size/XS label Mar 26, 2022
@CLAassistant
Copy link

CLAassistant commented Mar 26, 2022

CLA assistant check
All committers have signed the CLA.

mmcv/utils/config.py Outdated Show resolved Hide resolved
mmcv/utils/config.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@HAOCHENYE HAOCHENYE left a comment

Choose a reason for hiding this comment

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

It could be better if you can provide a corresponding unit test.

@jmercat
Copy link
Author

jmercat commented Mar 28, 2022

oops thanks for the review, I didn’t think this through I’ll give it another try...

it might be more convoluted than it needs to be but the formatting depends on the extension of the argument or the extension of the self.filename
@jmercat jmercat requested a review from HAOCHENYE March 28, 2022 05:23
@jmercat
Copy link
Author

jmercat commented Mar 28, 2022

When there is no input file argument, it does not save the config in a file but returns a string. I am not sure this is the desired behavior but the format of this string depends on self.filename (format of the string matching source format). I personally don’t think this is the best choice but I think this is the closest behavior to the previous version. (To me the dump string format should always be the same regardless of the source of the config.)

mmcv/utils/config.py Outdated Show resolved Hide resolved
@HAOCHENYE
Copy link
Collaborator

When there is no input file argument, it does not save the config in a file but returns a string. I am not sure this is the desired behavior but the format of this string depends on self.filename (format of the string matching source format). I personally don’t think this is the best choice but I think this is the closest behavior to the previous version. (To me the dump string format should always be the same regardless of the source of the config.)

Besides, it seems the original implementation will return python-format pretty_text regardless of the file format of file. It's a little weird, Maybe @zhouzaida could have a look.

@HAOCHENYE
Copy link
Collaborator

HAOCHENYE commented Mar 30, 2022

@jmercat Hi.

When there is no input file argument, it does not save the config in a file but returns a string. I am not sure this is the desired behavior but the format of this string depends on self.filename (format of the string matching source format). I personally don’t think this is the best choice but I think this is the closest behavior to the previous version. (To me the dump string format should always be the same regardless of the source of the config.)

Hi~ After discussing with my partners, your code implementation makes more sense and will not generate BC breaking risk. But there exists a small bug, If file and self.filename are None at the same time, mmcv.dump will raise an error.

@jmercat
Copy link
Author

jmercat commented Mar 30, 2022

Thanks for your reviews I’ll make these changes (name of the test and bug fix) tomorrow or Friday.

mmcv/utils/config.py Outdated Show resolved Hide resolved
@HAOCHENYE
Copy link
Collaborator

@jmercat Thanks for your docstring. But it seems the format is a little weird. Have you committed your code with pre-commit(https://github.com/open-mmlab/mmcv/blob/master/CONTRIBUTING.md)? Besides,
image
should be signed~

@zhouzaida
Copy link
Collaborator

Hi @jmercat , is there any progress?

@jmercat
Copy link
Author

jmercat commented Apr 21, 2022

I added other email addresses to my github account. I think it should solve the CLA signing problem.
I installed and ran the pre-commit and made changes in the docstring.

@jmercat
Copy link
Author

jmercat commented Apr 21, 2022

This is a good learning experience for me but I think that for such a small change, the formatting, cla, and all add an overhead that is larger than the contribution. Next time I’ll probably just write an issue, propose a code change there and let a bigger contributor implement it. It might even be faster for you, then you won’t need all these discussions as we had here. You might want to warn about this in the contribution guidelines.

@zhouzaida
Copy link
Collaborator

This is a good learning experience for me but I think that for such a small change, the formatting, cla, and all add an overhead that is larger than the contribution. Next time I’ll probably just write an issue, propose a code change there and let a bigger contributor implement it. It might even be faster for you, then you won’t need all these discussions as we had here. You might want to warn about this in the contribution guidelines.

Hi @jmercat, thanks for your contribution. You are welcome to open an issue to report anything.

@zhouzaida zhouzaida requested a review from ZwwWayne May 9, 2022 15:43
mmcv/utils/config.py Outdated Show resolved Hide resolved
mmcv/utils/config.py Outdated Show resolved Hide resolved
mmcv/utils/config.py Outdated Show resolved Hide resolved
@zhouzaida zhouzaida changed the title [FIX] config dump type handling [Fix] Fix dump method of Config May 10, 2022
@zhouzaida zhouzaida merged commit 1dbb5d3 into open-mmlab:master May 10, 2022
wangruohui pushed a commit to wangruohui/mmcv that referenced this pull request Jun 11, 2022
* config dump fix
dump should not depend on how config was loaded only where it is dumped
changed checks for type to the given filename instead of the source filename

* defined test_fromdict and fixed dump function
it might be more convoluted than it needs to be but the formatting depends on the extension of the argument or the extension of the self.filename

* config dump defaults to returning pretty_text, test_fromdict renamed to test_dump_from_dict

* some reformatting in docstrings

* refine unittest

* fix unit test as comment

* Refine docstring

* minor refinement

* import mmcv

* fix lint

Co-authored-by: HAOCHENYE <21724054@zju.edu.cn>
Co-authored-by: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants