You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/07/17 19:16:28 UTC

[GitHub] [incubator-mxnet] szha commented on a change in pull request #18368: [WIP] enable large tensor in np

szha commented on a change in pull request #18368:
URL: https://github.com/apache/incubator-mxnet/pull/18368#discussion_r456628889



##########
File path: tests/python/unittest/test_np_large_array.py
##########
@@ -0,0 +1,101 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import os
+import sys
+import tempfile
+import math
+import numpy as np
+import mxnet as mx
+
+curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
+sys.path.append(os.path.join(curr_path, '../python/unittest/'))
+
+from mxnet.test_utils import rand_ndarray, assert_almost_equal, rand_coord_2d, default_context, check_symbolic_forward, create_2d_tensor, use_np
+from mxnet import gluon, nd
+from common import with_seed
+import pytest
+
+
+# dimension constants
+SMALL_X = 100
+MEDIUM_X = 10000
+LARGE_X = 100000000
+VLARGE_X = 4300000000
+SMALL_Y = 50
+
+
+@use_np
+def test_gluon_embedding():
+    m = gluon.nn.Embedding(SMALL_Y, MEDIUM_X)
+    m.initialize()
+    a = mx.np.zeros((MEDIUM_X, SMALL_Y))
+    b = m(a)
+    assert b.shape == (MEDIUM_X, SMALL_Y, MEDIUM_X)
+    assert b.asnumpy().size == LARGE_X * SMALL_Y
+
+@use_np
+def test_fully_connected():
+    a = mx.np.ones(shape=(LARGE_X, SMALL_Y))
+    b = mx.np.ones(shape=(SMALL_Y, SMALL_Y))
+    c = mx.np.ones(shape=(b.shape[0],))
+
+    # w/o bias
+    res = mx.npx.FullyConnected(a, b, num_hidden=b.shape[0], no_bias=True)
+    assert np.sum(res[-1].asnumpy() == a.shape[1]) == b.shape[0]
+
+    # w/ bias
+    res = mx.npx.FullyConnected(a, b, c, num_hidden=b.shape[0], no_bias=False)
+    assert np.sum(res[-1].asnumpy() == a.shape[1] + 1) == b.shape[0]
+
+@use_np
+def test_dense():
+    data = mx.np.ones(shape=(50*1000*1000, 100))
+    linear = gluon.nn.Dense(100)
+    linear.initialize()
+    res = linear(data)
+    assert res.shape == (50000000, 100)

Review comment:
       yes will do




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org