Skip to content

Lazy evaluation - #582

Open
bgrant wants to merge 39 commits into
masterfrom
feature/lazy-evaluation
Open

Lazy evaluation#582
bgrant wants to merge 39 commits into
masterfrom
feature/lazy-evaluation

Conversation

@bgrant

Copy link
Copy Markdown
Contributor

Based on #580.

For example:

withcontext.lazy_eval():
a=context.zeros((52, 62))
b=context.ones((52, 62))
c=context.ones((52, 62)) +1d= (2*a+ (3*b+4*c)) /2e=globalapi.negative(d*d)

Our implementation

On the client, when <context>.lazy == True:

  • Sends are intercepted and queued (in <context>._sendq)
  • Recvs return immediately, queueing a lazy placeholder object inside a returned proxy object
  • When <context>.sync() is called, the both queues are sent to the engines (one queue per engine actually), and a real recv is blocked upon.

On the engines, when a 'process_message_queue' message is received (containing the queues):

  • Each message in the sendq is processed, one at a time, and the placeholder values from the recvq are used to feed values forward into the engine-side computation
  • Client-sends (return values) are queued, and sent as one message once the queue is processed.

On the client:

  • The client iterates through this return queue, and the lazy placeholders inside the originally reserved proxies are replaced by the real return values.

A note on my names

There's a Context attribute called lazy, and a Context method called lazy_eval() that is a context manager (decorated by contextlib.contextmanager) that sets and unsets lazy under the hood. If you have better ideas for those names, let me know.

Benchmark

I also added a simple benchmark in examples/lazy_eval. I time a loop that computes tanh on a DistArray for a settable number of iterations, both in lazy mode or in the default eager mode. Lazy mode seems to beat eager, but it's not as dramatic as I would have expected. I should probably think through the benchmark more.

@bgrantbgrant added this to the 0.6 milestone Aug 25, 2014
@bgrant

Copy link
Copy Markdown
ContributorAuthor

This is ready for a look @kwmsmith.

Conflicts:
distarray/globalapi/context.py
distarray/globalapi/tests/test_context.py
@kwmsmith

Copy link
Copy Markdown
Contributor

Closes #301

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here and below, looks like some pprints made it through.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Fixed.

@kwmsmith

Copy link
Copy Markdown
Contributor

There are 21 skips in the IPython test run -- is that normal?

@bgrant

Copy link
Copy Markdown
ContributorAuthor

I did add a bunch of MPI-only tests to test lazy-eval...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So does this allow you to create a context that is always lazy?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah, or at least lazy from the get-go. It really just sets <context>.lazy = True right off the bat. You can still set it to False later if you want.

@bgrant

Copy link
Copy Markdown
ContributorAuthor

Postponing to 0.7.

@bgrantbgrant modified the milestones: 0.7, 0.6Oct 16, 2015
Sign up for freeto 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.

2 participants

@bgrant@kwmsmith