def np_from_file(file_path, compresslevel):
  """Load numpy arrays from file_path with gzipping."""
  if not tf.io.gfile.exists(file_path):
    raise FileNotFoundError(file_path)
  res = []
  with tf.io.gfile.GFile(file_path, 'rb') as f:
    with gzip.GzipFile(fileobj=f, compresslevel=compresslevel) as gzipf:
      while True:
        try:
          res.append(np.load(gzipf, allow_pickle=False))
        except Exception:  # pylint: disable=broad-except
          break
  return res
Load numpy arrays from file_path with gzipping.
trax/layers/base.py