# Buggy code
def __init__(
    self,
    data: OutputData,
    latent_dim: int,
    X_data_mean: Optional[tf.Tensor] = None,
    kernel: Optional[Kernel] = None,
    mean_function: Optional[MeanFunction] = None,
):
    """
    Initialise GPLVM object. This method only works with a Gaussian likelihood.

    :param data: y data matrix, size N (number of points) x D (dimensions)
    :param latent_dim: the number of latent dimensions (Q)
    :param X_data_mean: latent positions ([N, Q]), for the initialisation of the latent space.
    :param kernel: kernel specification, by default Squared Exponential
    :param mean_function: mean function, by default None.
    """
    if X_data_mean is None:
        X_data_mean = pca_reduce(data, latent_dim)

    num_latent_gps = X_data_mean.shape[1]
    if num_latent_gps != latent_dim:
        msg = "Passed in number of latent {0} does not match initial X {1}."
        raise ValueError(msg.format(latent_dim, num_latent_gps))

    if mean_function is None:
        mean_function = Zero()

    if kernel is None:
        kernel = kernels.SquaredExponential(lengthscales=tf.ones((latent_dim,)))

    if data.shape[1] < num_latent_gps:
        raise ValueError("More latent dimensions than observed.")

    gpr_data = (Parameter(X_data_mean), data)
    super().__init__(gpr_data, kernel, mean_function=mean_function)


# 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: OutputData,
    latent_dim: int,
    X_data_mean: Optional[tf.Tensor] = None,
    kernel: Optional[Kernel] = None,
    mean_function: Optional[MeanFunction] = None,
):
    """
    Initialise GPLVM object. This method only works with a Gaussian likelihood.

    :param data: y data matrix, size N (number of points) x D (dimensions)
    :param latent_dim: the number of latent dimensions (Q)
    :param X_data_mean: latent positions ([N, Q]), for the initialisation of the latent space.
    :param kernel: kernel specification, by default Squared Exponential
    :param mean_function: mean function, by default None.
    """
    if X_data_mean is None:
        X_data_mean = pca_reduce(data, latent_dim)

    num_latent_gps = X_data_mean.shape[1]
    if num_latent_gps != latent_dim:
        msg = "Passed in number of latent {0} does not match initial X {1}."
        raise ValueError(msg.format(latent_dim, num_latent_gps))

    if mean_function is None:
        mean_function = Zero()

    if kernel is None:
        kernel = kernels.SquaredExponential(lengthscales=tf.ones((latent_dim,)))

    if data.shape[1] < num_latent_gps:
        raise ValueError("More latent dimensions than observed.")

    gpr_data = (Parameter(X_data_mean), data_input_to_tensor(data))
    super().__init__(gpr_data, kernel, mean_function=mean_function)