31 Commits

Author SHA1 Message Date
Jake Vanderplas
a7c2cdea64
Cleanup: convert uses of import numpy as onp in library code (#3754) 2020-07-14 13:05:31 -07:00
Jake Vanderplas
b813ae3aff
Cleanup: record names in get_module_functions (#3697) 2020-07-08 14:44:49 -07:00
Roy Frostig
fc4ab77bc6 merge constvars when forming cond branch jaxprs 2020-05-13 21:14:41 -07:00
George Necula
c52f32b59d
Removed unused imports (#2385)
Also disabled a couple more linalg tests that crash on my Mac
2020-03-09 20:42:08 +01:00
Peter Hawkins
e60d5dd54c
Remove "from __future__" uses from JAX. (#2117)
The future (Python 3) has arrived; no need to request it explicitly.
2020-01-29 12:29:03 -05:00
James Bradbury
a15aa9bd4d
include call stack + transforms in XLA metadata (#2073) 2020-01-26 23:27:56 -08:00
Peter Hawkins
681ba37f7e
Drop fastcache dependency, which isn't necessary on Python 3. (#1995)
Drop protobuf and six dependencies from travis configuration.
2020-01-14 10:08:23 -05:00
Matthew Johnson
ad9b6d4d94 implement lazy sublanguage
Before this commit, this computation would avoid materializing the iota
array at trace time:

  @jit
  def f(x):
    m, n = x.shape
    return x + np.arange(n)

But this one would materialize the iota array at trace time and stage it
into the computation as a potentially large array constant:

  @jit
  def f(x):
    m, n = x.shape
    return x + np.arange(m)[:, None]

The difference is that previously operations like broadcasts,
transposes, and reshapes that add singleton dimensions (as above) would
force otherwise lazy values to be materialized, while after this commit
broadcasts, transposes, and reshapes are all lazy operations that only
update metadata on their input rather than compiling and executing XLA
computations and producing new buffers.

Also, np.eye and np.tri become lazy (in addition to np.zeros, np.ones, np.full).

This commit replaces the ad-hoc "lazy device constant" system, which was
used to get the simpler behavior in the first example above.

Incidentally fixes #1431

See https://github.com/google/jax/pull/1668 for more.
2020-01-07 20:48:26 -08:00
Neeraj Pradhan
ed309b6f6a Fix for compatibility with python>=3.7 and numpy>=1.18 2020-01-01 08:17:55 -08:00
Jamie Townsend
f66aa275a6 Rm duplicates from end_nodes in toposort 2019-10-01 17:56:44 +01:00
Matthew Johnson
b702f8de3e De-tuplify the rest of the core
Co-authored-by: Dougal Maclaurin <dougalm@google.com>
2019-08-21 13:21:20 -07:00
Dougal Maclaurin
6d71396d56 Start exploring jaxprs without tuples
Co-authored-by: Matthew Johnson <mattjj@google.com>
2019-08-21 07:01:07 -07:00
Peter Hawkins
a8ddf071bd Add test case for concurrent device_get and device_put calls.
Fix concurrency problems in memoize_... decorators.
Rename util.memoize to util.cache.
Remove util.memoize_unary and xla_bridge.memoize_thunk, replace with more general and thread-safe util.memoize that wraps fastcache.
2019-08-09 13:12:44 -04:00
Peter Hawkins
a94600c407 Optimizations to pmap computation launch time. 2019-08-05 14:08:46 -04:00
Peter Hawkins
08013954a4 Use fastcache for LRU caches in JAX.
fastcache is both a faster cache implementation and is also thread-safe.
2019-07-22 17:24:10 -04:00
Matthew Johnson
8bc4e379f5 make DeviceArray.__hash__ raise an error
Fixes #883 by adjusting the caching logic we use not to rely on
DeviceArray being hashable, also closing a long-standing TODO.

Also fixed a minor bug in lax.py which caused scalar DeviceArrays to
appear in the padding params of some convolutions (from using `max`
instead of `_max` in lax.py).
2019-06-19 10:12:13 -07:00
Matthew Johnson
5aea10c7b3 make static_argnums cache on value when possible
fixes #691
2019-05-09 20:00:24 -07:00
Matthew Johnson
25479c3518 fix pmap performance bug, dont always copy to host 2019-03-26 08:35:34 -07:00
Peter Hawkins
1800d6554d Add comments to linear_util.py. 2019-03-12 15:07:52 -04:00
Peter Hawkins
2b383bdbd9 Increase cache size to 4096. 2019-01-15 10:32:58 -05:00
Peter Hawkins
3266bb3122 Change linear_util.memoize to use an LRU cache.
Add util.OrderedDict that retrofits a move_to_end method onto Python 2 OrderedDicts.
2019-01-14 21:48:28 -05:00
Peter Hawkins
05b1049e49 Change util.memoize to be an LRU cache with a default size of 64 entries.
The goal is to limit peak memory when running a large number of computations, e.g., the test suite.
2019-01-14 20:11:08 -05:00
Peter Hawkins
8127392a18 Use get() rather than a try-catch block in memoized function lookup.
Currently backtraces often look like this:
```
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/p/jax/jax/util.py in memoized_fun(*args, **kwargs)
    133     try:
--> 134       return cache[key]
    135     except KeyError:

KeyError: ((lu, ShapedArray(int32[2,2])), ())

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
~/p/jax/jax/util.py in memoized_fun(*args, **kwargs)
    133     try:
--> 134       return cache[key]
    135     except KeyError:

KeyError: ((lu, xla_client.Shape(_dtype=dtype('int32'), _dimensions=(2, 2), _is_tuple=False, _minor_to_major=None)), ())

During handling of the above exception, another exception occurred:

NotImplementedError                       Traceback (most recent call last)
<ipython-input-26-d6c00d50e3c9> in <module>
```

The "during handling of the above exception..." message is mostly a distraction for the user that occurs because we perform the memoized function evaluation inside a `catch` block. By performing the function evaluation outside the catch block, we can get better backtraces without the distraction of the KeyError exception.

```
2018-12-21 13:32:56 -05:00
Alex Wiltschko
763f860135 Automated detection of unimplemented functions 2018-12-11 11:52:31 -05:00
Dougal Maclaurin
30124b6da1 Added jit transformations to generated functions. Fixed bug in comparing numpy arrays for equality. 2018-12-08 00:03:34 -05:00
Dougal Maclaurin
307d195577 Wrapped static args to jit to be hashed on id. This is conservative but simple and cheap. 2018-12-05 15:55:01 -05:00
Dougal Maclaurin
ca2634ea5d source sync
PiperOrigin-RevId: 222923229
2018-11-27 16:51:22 -08:00
Peter Hawkins
5e60639bc5 source sync
PiperOrigin-RevId: 222452709
2018-11-21 20:22:54 -08:00
Peter Hawkins
e180f08113 source sync
PiperOrigin-RevId: 222451919
2018-11-21 20:22:51 -08:00
Peter Hawkins
fe4edf2839 source sync
PiperOrigin-RevId: 222449830
2018-11-21 20:22:49 -08:00
Matthew Johnson
a30e858e59 populating source tree 2018-11-17 18:03:33 -08:00