Created
March 27, 2018 07:35
-
-
Save fehiepsi/00f7b2fdfcc7bf39ee25968bad40f6db to your computer and use it in GitHub Desktop.
pyro test error?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import torch\n", | |
| "import pyro.contrib.gp as gp" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[26.230701446533203]" | |
| ] | |
| }, | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "X = torch.tensor([[1, 5, 3], [4, 3, 7]])\n", | |
| "y2D = torch.tensor([[1, 2], [3, 3], [1, 4], [-1, 1]])\n", | |
| "kernel = gp.kernels.RBF(input_dim=3, variance=torch.tensor([1]), lengthscale=torch.tensor([3]))\n", | |
| "noise = torch.tensor([1e-6])\n", | |
| "\n", | |
| "gp = gp.models.GPRegression(X, y2D, kernel, noise)\n", | |
| "gp.optimize(num_steps=1)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "============================= test session starts ==============================\n", | |
| "platform linux -- Python 3.5.4, pytest-3.3.2, py-1.5.2, pluggy-0.6.0 -- /home/fehiepsi/miniconda3/envs/pyro/bin/python\n", | |
| "cachedir: .cache\n", | |
| "benchmark: 3.1.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)\n", | |
| "rootdir: /home/fehiepsi/pyro, inifile: setup.cfg\n", | |
| "plugins: xdist-1.22.1, forked-0.2, cov-2.5.1, benchmark-3.1.1, nbval-0.7\n", | |
| "collecting ... collected 1 item\n", | |
| "\n", | |
| "tests/contrib/gp/test_models.py::test_inference[GPRegression_y2D] FAILED [100%]\n", | |
| "\n", | |
| "=================================== FAILURES ===================================\n", | |
| "_______________________ test_inference[GPRegression_y2D] _______________________\n", | |
| "\n", | |
| "model_class = <class 'pyro.contrib.gp.models.gpr.GPRegression'>\n", | |
| "X = \n", | |
| " 1 5 3\n", | |
| " 4 3 7\n", | |
| "[torch.DoubleTensor of size (2,3)]\n", | |
| "\n", | |
| "y = \n", | |
| " 1 2\n", | |
| " 3 3\n", | |
| " 1 4\n", | |
| "-1 1\n", | |
| "[torch.DoubleTensor of size (4,2)]\n", | |
| "\n", | |
| "kernel = RBF(\n", | |
| ")\n", | |
| "likelihood = \n", | |
| "1.00000e-06 *\n", | |
| " 1.0000\n", | |
| "[torch.DoubleTensor of size (1,)]\n", | |
| "\n", | |
| "\n", | |
| " @pytest.mark.parametrize(\"model_class, X, y, kernel, likelihood\", TEST_CASES, ids=TEST_IDS)\n", | |
| " def test_inference(model_class, X, y, kernel, likelihood):\n", | |
| " if model_class is SparseGPRegression or model_class is SparseVariationalGP:\n", | |
| " gp = model_class(X, y, kernel, X, likelihood)\n", | |
| " else:\n", | |
| " gp = model_class(X, y, kernel, likelihood)\n", | |
| " \n", | |
| "> gp.optimize(num_steps=1)\n", | |
| "\n", | |
| "tests/contrib/gp/test_models.py:110: \n", | |
| "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n", | |
| "pyro/contrib/gp/models/model.py:76: in optimize\n", | |
| " losses.append(svi.step())\n", | |
| "pyro/infer/svi.py:97: in step\n", | |
| " loss = self.loss_and_grads(self.model, self.guide, *args, **kwargs)\n", | |
| "pyro/infer/trace_elbo.py:84: in loss_and_grads\n", | |
| " for model_trace, guide_trace in self._get_traces(model, guide, *args, **kwargs):\n", | |
| "pyro/infer/trace_elbo.py:50: in _get_traces\n", | |
| " check_site_shape(site, self.max_iarange_nesting)\n", | |
| "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n", | |
| "\n", | |
| "site = {'args': (), 'batch_log_pdf': \n", | |
| "-4.0054\n", | |
| "-9.3196\n", | |
| "-9.8386\n", | |
| "-3.0670\n", | |
| "[torch.DoubleTensor of size (4,)]\n", | |
| ", 'cond_indep_stack': (), 'continuation': None, ...}\n", | |
| "max_iarange_nesting = inf\n", | |
| "\n", | |
| " def check_site_shape(site, max_iarange_nesting):\n", | |
| " actual_shape = list(site[\"batch_log_pdf\"].shape)\n", | |
| " \n", | |
| " # Compute expected shape.\n", | |
| " expected_shape = []\n", | |
| " for f in site[\"cond_indep_stack\"]:\n", | |
| " if f.dim is not None:\n", | |
| " # Use the specified iarange dimension, which counts from the right.\n", | |
| " assert f.dim < 0\n", | |
| " if len(expected_shape) < -f.dim:\n", | |
| " expected_shape = [None] * (-f.dim - len(expected_shape)) + expected_shape\n", | |
| " if expected_shape[f.dim] is not None:\n", | |
| " raise ValueError('\\n '.join([\n", | |
| " 'at site \"{}\" within iarange(\"\", dim={}), dim collision'.format(site[\"name\"], f.name, f.dim),\n", | |
| " 'Try setting dim arg in other iaranges.']))\n", | |
| " expected_shape[f.dim] = f.size\n", | |
| " expected_shape = [1 if e is None else e for e in expected_shape]\n", | |
| " \n", | |
| " # Check for iarange stack overflow.\n", | |
| " if len(expected_shape) > max_iarange_nesting:\n", | |
| " raise ValueError('\\n '.join([\n", | |
| " 'at site \"{}\", iarange stack overflow'.format(site[\"name\"]),\n", | |
| " 'Try increasing max_iarange_nesting to at least {}'.format(len(expected_shape))]))\n", | |
| " \n", | |
| " # Ignore dimensions left of max_iarange_nesting.\n", | |
| " if max_iarange_nesting < len(actual_shape):\n", | |
| " actual_shape = actual_shape[len(actual_shape) - max_iarange_nesting:]\n", | |
| " \n", | |
| " # Check for incorrect iarange placement on the right of max_iarange_nesting.\n", | |
| " for actual_size, expected_size in zip_longest(reversed(actual_shape), reversed(expected_shape), fillvalue=1):\n", | |
| " if expected_size != -1 and expected_size != actual_size:\n", | |
| " raise ValueError('\\n '.join([\n", | |
| " 'at site \"{}\", invalid log_prob shape'.format(site[\"name\"]),\n", | |
| " 'Expected {}, actual {}'.format(expected_shape, actual_shape),\n", | |
| " 'Try one of the following fixes:',\n", | |
| " '- enclose the batched tensor in a with iarange(...): context',\n", | |
| " '- .reshape(extra_event_dims=...) the distribution being sampled',\n", | |
| "> '- .permute() data dimensions']))\n", | |
| "E ValueError: at site \"y\", invalid log_prob shape\n", | |
| "E Expected [], actual [4]\n", | |
| "E Try one of the following fixes:\n", | |
| "E - enclose the batched tensor in a with iarange(...): context\n", | |
| "E - .reshape(extra_event_dims=...) the distribution being sampled\n", | |
| "E - .permute() data dimensions\n", | |
| "\n", | |
| "pyro/util.py:406: ValueError\n", | |
| "=========================== 1 failed in 0.12 seconds ===========================\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "%cat ~/pyro/error.txt" | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python (pyro)", | |
| "language": "python", | |
| "name": "pyro" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.5.4" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment