Skip to content

Latest commit

 

History

History
64 lines (40 loc) · 1.47 KB

execution.rst

File metadata and controls

64 lines (40 loc) · 1.47 KB

Local Execution

Mars tensor will not be executed unless users call execute or session.run methods.

If no session is created explicitly, the execute will create a local session, and mark it as a default session.

Session

Users can create a new session by new_session method, if no argument is provided, a local session will be generated.

>>> from mars.session import new_session

>>> sess = new_session()  # create a session

By calling as_default of a session, the session will be marked as the default session.

>>> sess.as_default()

More than one mars tensors can be passed to session.run, and calculate the results for each tensor.

>>> a = mt.ones((5, 5), chunk_size=3)
>>> b = a + 1
>>> c = a * 4
>>> sess.run(b, c)
(array([[2., 2., 2., 2., 2.],
     [2., 2., 2., 2., 2.],
     [2., 2., 2., 2., 2.],
     [2., 2., 2., 2., 2.],
     [2., 2., 2., 2., 2.]]), array([[4., 4., 4., 4., 4.],
     [4., 4., 4., 4., 4.],
     [4., 4., 4., 4., 4.],
     [4., 4., 4., 4., 4.],
     [4., 4., 4., 4., 4.]]))

Execute a tensor

For a single tensor, execute can be called.

>>> a = mt.random.rand(3, 4)
>>> a.sum().execute()
7.0293719034458455

Session can be specified by the argument session=.

>>> a.sum().execute(session=sess)
6.12833989477539