Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

support regex of collect_params() #9348

Merged
merged 12 commits into from
Jan 12, 2018
Merged

support regex of collect_params() #9348

merged 12 commits into from
Jan 12, 2018

Conversation

tornadomeet
Copy link
Contributor

@tornadomeet tornadomeet commented Jan 8, 2018

Description

#9323

Checklist

Essentials

  • Passed code style checking (make lint)
  • Changes are complete (i.e. I finished coding on this PR)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

@szha select name and function comments may be improved. if these change is ok, i'll add unit test here.

@@ -227,13 +228,37 @@ def params(self):
children's parameters)."""
return self._params

def collect_params(self):
def collect_params(self, select=['.*']):
Copy link
Contributor

Choose a reason for hiding this comment

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

select should be None by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, will change this.

Parameters
----------
select : list of str
List of name or regular expressions
Copy link
Contributor

Choose a reason for hiding this comment

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

Only support 1 regex, not a list

Copy link
Contributor Author

@tornadomeet tornadomeet Jan 9, 2018

Choose a reason for hiding this comment

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

Done. @piiswrong

another, if user has a python list to select parameter, like ['a', 'b', 'c'], t hen he/she should first convert select='a|b|c' first using some code, any better way to avoid this?

ret = ParameterDict(self._params.prefix)
ret.update(self.params)
if select is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

don't do any regex matching if select is None. Its very slow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@piiswrong Done.

@chinakook
Copy link
Contributor

wonderful.

else:
for name in self.params.keys():
if re.compile(select).match(name):
ret.update({name:self.params[name]})
Copy link
Member

@szha szha Jan 10, 2018

Choose a reason for hiding this comment

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

pattern = re.compile(select)
ret.update({name: value for name, value in self.params.items() if pattern.match(name)}

Copy link
Member

Choose a reason for hiding this comment

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

Compiling a pattern that don't change can be expensive especially inside the for loop. I wonder if we should cache the compiled object and pass it to the recursive calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@szha Done.

@@ -253,7 +253,7 @@ def collect_params(self, select=None):
The selected :py:class:`ParameterDict`
"""
ret = ParameterDict(self._params.prefix)
if select is None:
if not select:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if select = [] or {} or '' or () then not select will be True, may be wrong here.

Copy link
Member

Choose a reason for hiding this comment

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

You're right, and it should be fine as long as both empty string and None returns true.

@piiswrong piiswrong merged commit 4600070 into apache:master Jan 12, 2018
@tornadomeet tornadomeet deleted the filter branch January 14, 2018 07:22
CodingCat pushed a commit to CodingCat/mxnet that referenced this pull request Jan 16, 2018
* support regex of collect_params()

* fix pylint

* change default value && make select as a sigle reg

* fix if select is None, then will not do any regex matching

* update regex compile && add test

* Update block.py

* support regex of collect_params()

* fix pylint

* change default value && make select as a sigle reg

* fix if select is None, then will not do any regex matching

* update regex compile && add test
yuxiangw pushed a commit to yuxiangw/incubator-mxnet that referenced this pull request Jan 25, 2018
* support regex of collect_params()

* fix pylint

* change default value && make select as a sigle reg

* fix if select is None, then will not do any regex matching

* update regex compile && add test

* Update block.py

* support regex of collect_params()

* fix pylint

* change default value && make select as a sigle reg

* fix if select is None, then will not do any regex matching

* update regex compile && add test
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
* support regex of collect_params()

* fix pylint

* change default value && make select as a sigle reg

* fix if select is None, then will not do any regex matching

* update regex compile && add test

* Update block.py

* support regex of collect_params()

* fix pylint

* change default value && make select as a sigle reg

* fix if select is None, then will not do any regex matching

* update regex compile && add test
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
* support regex of collect_params()

* fix pylint

* change default value && make select as a sigle reg

* fix if select is None, then will not do any regex matching

* update regex compile && add test

* Update block.py

* support regex of collect_params()

* fix pylint

* change default value && make select as a sigle reg

* fix if select is None, then will not do any regex matching

* update regex compile && add test
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants