# Buggy code
def __init__(
    self,
    data: RegressionData,
    kernel: Kernel,
    likelihood: Likelihood,
    mean_function: Optional[MeanFunction] = None,
    num_latent_gps: Optional[int] = None,
):
    """
    data is a tuple of X, Y with X, a data matrix, size [N, D] and Y, a data matrix, size [N, R]
    kernel, likelihood, mean_function are appropriate GPflow objects

    This is a vanilla implementation of a GP with a non-Gaussian
    likelihood. The latent function values are represented by centered
    (whitened) variables, so

        v ~ N(0, I)
        f = Lv + m(x)

    with

        L L^T = K

    """
    if num_latent_gps is None:
        num_latent_gps = self.calc_num_latent_gps_from_data(data, kernel, likelihood)
    super().__init__(kernel, likelihood, mean_function, num_latent_gps)
    self.data = data
    self.num_data = data[0].shape[0]
    self.V = Parameter(np.zeros((self.num_data, self.num_latent_gps)))
    self.V.prior = tfp.distributions.Normal(
        loc=to_default_float(0.0), scale=to_default_float(1.0)
    )


# Traceback (ValueError)
Traceback (most recent call last):
File "main.py", line 177, in <module>
main(args)
File "main.py", line 64, in main
build_allele(args)
File "/path/to/1_model_sim/drivers.py", line 226, in build_allele
opt_model_list(m)
File "/path/to/1_model_sim/model.py", line 355, in opt_model_list
m.trainable_variables)
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/gpflow/optimizers/scipy.py", line 73, in minimize
func, initial_params, jac=True, method=method, **scipy_kwargs
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/scipy/optimize/_minimize.py", line 610, in minimize
callback=callback, **options)
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/scipy/optimize/lbfgsb.py", line 345, in _minimize_lbfgsb
f, g = func_and_grad(x)
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/scipy/optimize/lbfgsb.py", line 295, in func_and_grad
f = fun(x, *args)
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/scipy/optimize/optimize.py", line 327, in function_wrapper
return function(*(wrapper_args + args))
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/scipy/optimize/optimize.py", line 65, in __call__
fg = self.fun(x, *args)
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/gpflow/optimizers/scipy.py", line 95, in _eval
loss, grad = _tf_eval(tf.convert_to_tensor(x))
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/def_function.py", line 568, in __call__
result = self._call(*args, **kwds)
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/def_function.py", line 615, in _call
self._initialize(args, kwds, add_initializers_to=initializers)
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/def_function.py", line 497, in _initialize
*args, **kwds))
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 2389, in _get_concrete_function_internal_garbage_collected
graph_function, _, _ = self._maybe_define_function(args, kwargs)
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 2703, in _maybe_define_function
graph_function = self._create_graph_function(args, kwargs)
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 2593, in _create_graph_function
capture_by_value=self._capture_by_value),
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/func_graph.py", line 978, in func_graph_from_py_func
func_outputs = python_func(*func_args, **func_kwargs)
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/eager/def_function.py", line 439, in wrapped_fn
return weak_wrapped_fn().__wrapped__(*args, **kwds)
File "/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/func_graph.py", line 968, in wrapper
raise e.ag_error_metadata.to_exception(e)
ValueError: in converted code:

/path/to/1_model_sim/venv/lib/python3.6/site-packages/gpflow/optimizers/scipy.py:88 _tf_eval  *
loss, grads = _compute_loss_and_gradients(closure, variables)
/path/to/1_model_sim/venv/lib/python3.6/site-packages/gpflow/optimizers/scipy.py:145 _compute_loss_and_gradients  *
loss = loss_closure()
/path/to/1_model_sim/model.py:354 None  *
opt.minimize(lambda: - m.log_marginal_likelihood(),
/path/to/1_model_sim/venv/lib/python3.6/site-packages/gpflow/models/gpr.py:75 log_marginal_likelihood  *
log_prob = multivariate_normal(Y, m, L)
/path/to/1_model_sim/venv/lib/python3.6/site-packages/gpflow/logdensities.py:95 multivariate_normal  *
d = x - mu
/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/ops/math_ops.py:927 r_binary_op_wrapper
x = ops.convert_to_tensor(x, dtype=y.dtype.base_dtype, name="x")
/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py:1314 convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/tensor_conversion_registry.py:52 _default_conversion_function
return constant_op.constant(value, dtype, name=name)
/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/constant_op.py:258 constant
allow_broadcast=True)
/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/constant_op.py:296 _constant_impl
allow_broadcast=allow_broadcast))
/path/to/1_model_sim/venv/lib/python3.6/site-packages/tensorflow_core/python/framework/tensor_util.py:522 make_tensor_proto
"Cannot create a tensor proto whose content is larger than 2GB.")

ValueError: Cannot create a tensor proto whose content is larger than 2GB.

# Fixed code
def __init__(
    self,
    data: RegressionData,
    kernel: Kernel,
    likelihood: Likelihood,
    mean_function: Optional[MeanFunction] = None,
    num_latent_gps: Optional[int] = None,
):
    """
    data is a tuple of X, Y with X, a data matrix, size [N, D] and Y, a data matrix, size [N, R]
    kernel, likelihood, mean_function are appropriate GPflow objects

    This is a vanilla implementation of a GP with a non-Gaussian
    likelihood. The latent function values are represented by centered
    (whitened) variables, so

        v ~ N(0, I)
        f = Lv + m(x)

    with

        L L^T = K

    """
    if num_latent_gps is None:
        num_latent_gps = self.calc_num_latent_gps_from_data(data, kernel, likelihood)
    super().__init__(kernel, likelihood, mean_function, num_latent_gps)
    self.data = data_input_to_tensor(data)
    self.num_data = self.data[0].shape[0]
    self.V = Parameter(np.zeros((self.num_data, self.num_latent_gps)))
    self.V.prior = tfp.distributions.Normal(
        loc=to_default_float(0.0), scale=to_default_float(1.0)
    )