Skip to content

Guard NumPy usage using USE_NUMPY#11798

Closed
vishwakftw wants to merge 8 commits intopytorch:masterfrom
vishwakftw:no-numpy-build-test
Closed

Guard NumPy usage using USE_NUMPY#11798
vishwakftw wants to merge 8 commits intopytorch:masterfrom
vishwakftw:no-numpy-build-test

Conversation

@vishwakftw
Copy link
Contributor

All usages of the ndarray construct have now been guarded with USE_NUMPY. This eliminates the requirement of NumPy while building PyTorch from source.

Fixes #11757

cc: @apaszke

Maybe this'll work.
Copy link
Contributor

@apaszke apaszke left a comment

Choose a reason for hiding this comment

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

cc @Yangqing for review

const auto it = numpy_type_map.find(meta.id());
return it == numpy_type_map.end() ? -1 : it->second;
#else
return -1;

This comment was marked as off-topic.

return it == caffe_type_map.end() ? unknown_type : it->second;
#else
static TypeMeta unknown_type;
return unknown_type;

This comment was marked as off-topic.

@Yangqing
Copy link
Contributor

So, regarding the test failures you encounter, it is because the -DUSE_NUMPY is only passed to cmake but not passed down to the compilers. To do so, you should add

#cmakedefine USE_NUMPY

in caffe2/core/macros.h.in and you should be able to properly get the with-numpy version. Thanks so much for the rest of the PR! It looks great.

@Yangqing
Copy link
Contributor

By the way, when importing this into Facebook internal code, we will need to add the USE_NUMPY macro in our internal build as well, so I'll self-assign this PR to myself to import.

@Yangqing Yangqing self-assigned this Sep 19, 2018
@vishwakftw
Copy link
Contributor Author

Thank you @Yangqing for the solution. I think I've done the necessary as advised, the tests should pass now I suppose.

@vishwakftw
Copy link
Contributor Author

The test failures persist, originating from the same place as earlier.

@vishwakftw
Copy link
Contributor Author

All tests pass now, the test failures are related to DDP.

@vishwakftw
Copy link
Contributor Author

@apaszke could I get a review on this?

@vishwakftw
Copy link
Contributor Author

@Yangqing could I get a review on this?

@vishwakftw
Copy link
Contributor Author

@pytorchbot retest this please

@vishwakftw
Copy link
Contributor Author

Now all the builds have passed. I think the fix is right.

@ssnl ssnl removed the caffe2 label Sep 25, 2018
@ssnl
Copy link
Collaborator

ssnl commented Sep 25, 2018

@Yangqing @apaszke Is this good to go?

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

SsnL has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@apaszke apaszke left a comment

Choose a reason for hiding this comment

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

Can we please revert the PyArrayObject -> PyObject change?

void FeedTensor(
const DeviceOption& option,
PyArrayObject* original_array,
PyObject* original_array,

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

Copy link
Contributor

@apaszke apaszke left a comment

Choose a reason for hiding this comment

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

LGTM, but @Yangqing might want to stamp this too

@vishwakftw
Copy link
Contributor Author

@Yangqing is this good to go?

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

SsnL is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

SsnL has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@ssnl
Copy link
Collaborator

ssnl commented Sep 29, 2018

extra places to be guarded:

std::vector<npy_intp> npy_dims;

npy_intp* npy_dims = PyArray_DIMS(array);

std::vector<npy_intp> npy_dims;

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

SsnL has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@ssnl
Copy link
Collaborator

ssnl commented Sep 30, 2018

@apaszke @Yangqing This patch somehow makes internal caffe2 compiled without numpy support... See the fbcode tests failures.

@vishwakftw
Copy link
Contributor Author

@ssnl Will this comment help?

By the way, when importing this into Facebook internal code, we will need to add the USE_NUMPY macro in our internal build as well, so I'll self-assign this PR to myself to import.

@ssnl
Copy link
Collaborator

ssnl commented Oct 4, 2018

@vishwakftw I talked with yangqing and I'm patching internal build right now.

@vishwakftw
Copy link
Contributor Author

Thank you @ssnl for working on this.

facebook-github-bot pushed a commit that referenced this pull request Oct 4, 2018
Summary:
All usages of the `ndarray` construct have now been guarded with `USE_NUMPY`. This eliminates the requirement of NumPy while building PyTorch from source.

Fixes #11757

Reviewed By: Yangqing

Differential Revision: D10031862

Pulled By: SsnL

fbshipit-source-id: 32d84fd770a7714d544e2ca1895a3d7c75b3d712
@vishwakftw vishwakftw closed this Oct 4, 2018
@vishwakftw vishwakftw deleted the no-numpy-build-test branch October 7, 2018 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to build PyTorch from source without NumPy support

7 participants