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

Refine runtime feature discovery python API and add documentation to … #14130

Merged
merged 12 commits into from
Feb 18, 2019

Conversation

larroy
Copy link
Contributor

@larroy larroy commented Feb 12, 2019

…Python API docs

Description

see title

@aaronmarkham

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • 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)
  • 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
  • Check the API doc at http:https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Decode feature name to string since it comes as a buffer
  • Add repr as beautifier

@larroy larroy requested a review from szha as a code owner February 12, 2019 10:40
@larroy larroy force-pushed the feature_discovery branch 2 times, most recently from 5da0748 to 7a39b9a Compare February 12, 2019 14:31
✔ DIST_KVSTORE,
✔ CXX14,
✔ SIGNAL_HANDLER,
✖ DEBUG]
Copy link
Member

Choose a reason for hiding this comment

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

❤️ this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied from you :-)

@ankkhedia
Copy link
Contributor

@larroy Thanks for your contribution!
@mxnet-label-bot add [pr-awaiting-review, Doc]

@marcoabreu marcoabreu added Doc pr-awaiting-review PR is waiting for code review labels Feb 12, 2019
feature_dict = {f.name: f.enabled for f in libinfo_features()}
if tocheck not in feature_dict:
raise RuntimeError("Feature '{}' is unknown, known features are: {}".format(tocheck, list(feature_dict.keys())))
return feature_dict[tocheck]
Copy link
Member

Choose a reason for hiding this comment

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

if a dictionary is easier to operate, should the libinfo_features return a dictionary?

Copy link
Contributor Author

@larroy larroy Feb 12, 2019

Choose a reason for hiding this comment

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

I prefer to keep ordering as in a list. Going from list to dict is oneliner. Also we don't get a dict from C.

Copy link
Member

Choose a reason for hiding this comment

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

is the order information useful? I always thought of it as a set. also, by defining your own data structure class, you can define more pythonic behaviors such as __contains__ and __getitem__ to make it easier for feature check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are grouped if you see the enum definition as some features are related, semantically is a set as you describe. For using contains as you propose we would have to wrap the list in a containing class. I don't see a lot of value on complicating this further TBH. Could you provide an example of what you have in mind if you feel strongly about it?

Copy link
Member

Choose a reason for hiding this comment

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

I don't feel stongly about the change. What I had in mind was something like:

>>> features = mx.runtime.libinfo_features()
>>> 'NCCL' in features
True
>>> 'nccl' in features
True
>>> nccl_idx = 2;
>>> nccl_idx in features
True
>>> features['NCCL']
✔ NCCL
>>> features['NCCL'].index
2
>>> features['NCCL'].enabled
True

Copy link
Contributor Author

@larroy larroy Feb 13, 2019

Choose a reason for hiding this comment

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

I see, that looks nice. On the upside repeated calls are more efficient than my proposal. On the downside I think the primary case which is to check if a feature is enabled is less ergonomic due to the syntactic sugar. I think a simple function with a single arg is always clearer. A good point is that it should be case insensitive. I'm a bit torn. I will refine it a bit more.

Copy link
Contributor

@apeforest apeforest Feb 13, 2019

Choose a reason for hiding this comment

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

Just curious: is the index information useful to user? Why do we even need to expose index?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@apeforest I just removed it.

@@ -29,6 +29,17 @@ def test_libinfo_features():
ok_(type(features) is list)
ok_(len(features) > 0)

def test_is_enabled():
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this test run in a docker image with CUDA on the machine without GPU?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I get what's the intention.

@larroy
Copy link
Contributor Author

larroy commented Feb 14, 2019

I made the suggested changed, please have another look and merge if you are good with it, thanks.

@szha szha merged commit 3a6fe22 into apache:master Feb 18, 2019
jessr92 pushed a commit to jessr92/incubator-mxnet that referenced this pull request Feb 19, 2019
apache#14130)

* Refine runtime feature discovery python API and add documentation to Python API docs

* Fix lint

* Provide is_enabled method to check if feature is present from string

* Refine docs, add is_enabled

* Fix encoding

* Fix doc

* Address CR suggestions

* remove index as per CR suggestion

* Fix lint

* runtime

* Fix doc

* Add license
@larroy
Copy link
Contributor Author

larroy commented Feb 19, 2019

Thanks for the merge and the review.

drivanov pushed a commit to drivanov/incubator-mxnet that referenced this pull request Mar 4, 2019
apache#14130)

* Refine runtime feature discovery python API and add documentation to Python API docs

* Fix lint

* Provide is_enabled method to check if feature is present from string

* Refine docs, add is_enabled

* Fix encoding

* Fix doc

* Address CR suggestions

* remove index as per CR suggestion

* Fix lint

* runtime

* Fix doc

* Add license
vdantu pushed a commit to vdantu/incubator-mxnet that referenced this pull request Mar 31, 2019
apache#14130)

* Refine runtime feature discovery python API and add documentation to Python API docs

* Fix lint

* Provide is_enabled method to check if feature is present from string

* Refine docs, add is_enabled

* Fix encoding

* Fix doc

* Address CR suggestions

* remove index as per CR suggestion

* Fix lint

* runtime

* Fix doc

* Add license
haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
apache#14130)

* Refine runtime feature discovery python API and add documentation to Python API docs

* Fix lint

* Provide is_enabled method to check if feature is present from string

* Refine docs, add is_enabled

* Fix encoding

* Fix doc

* Address CR suggestions

* remove index as per CR suggestion

* Fix lint

* runtime

* Fix doc

* Add license
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Doc pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants