Primitive to sequentially execute a function inside a vmapped function
See original GitHub issueI am writing some longer algorithms which I like to vmap. I stumbled over some problems when combining vmap with the host_callback
module and the lax.cond
function:
- vmap of cond does not work when the branches are not side-effect-free
- vmap of cond of can be very ineffective if one branch is much longer but only called rarely
- There is no trivial batching rule for the
host_callback.call
function
I think a simple solution would be to implement a stop_vmap
or sequential_vmap
decorator. This decorator would define a batching rule, such that
@vmap
@stop_vmap
def some_fun(*args):
# Some operations ...
return results
would be the same as writing
def some_fun(*batched_args):
def body_fun(*args):
# Some operation...
return results
return lax.map(lambda args: body_fun(*args), batched_args)
The advantage of the decorator would be that some_fun
could be used inside a much bigger vmapped function.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7 (5 by maintainers)
Top Results From Across the Web
javascript - How to execute promises sequentially, passing the ...
In my actual use case the array is dynamically populated and I need to execute the myPromise() function for each member in myArray...
Read more >2.1. Primitive Tensor Function - Machine Learning Compilation
Primitive tensor function refers to the single unit of computation in model execution. A MLC process can choose to transform implementation of primitive...
Read more >21 Iteration | R for Data Science - Hadley Wickham
In this chapter you'll learn about two important iteration paradigms: imperative programming and functional programming. On the imperative side you have tools ...
Read more >XPath and XQuery Functions and Operators 3.1 - W3C
For a sequence of calls within the same ·execution scope·, ... The diagrams in this section show how nodes, functions, primitive simple ...
Read more >Built-in Types — Python 3.11.1 documentation
Operations and built-in functions that have a Boolean result always return ... the machine on which your program is running is available in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
More general “custom batching” could be interesting for use-cases like
host_callback.call
, where some external library that may support its own parallelism strategies. E.g., I think this could be useful for @ianwilliamson’s MEEP wrapper: https://github.com/NanoComp/meep/pull/1569This could definitely be a good place to start, even if only as the first step towards the general solution.
I tend to agree, like having written
linear_call
as a first step towards custom transposition. Perhaps worth trying to see what it surfaces.