Skip to content

Switch to using PyTorch distributions by default#676

Merged
neerajprad merged 9 commits intodevfrom
wrap-torch-distributions
Jan 13, 2018
Merged

Switch to using PyTorch distributions by default#676
neerajprad merged 9 commits intodevfrom
wrap-torch-distributions

Conversation

@fritzo
Copy link
Copy Markdown
Member

@fritzo fritzo commented Jan 12, 2018

This flips the switch to start using PyTorch distributions by default, only if they are available. If they are not available (i.e. if an older PyTorch version is installed), then the old Pyro distributions will be used instead.

Note that a few Pyro distributions are currently being implemented in PyTorch, and are not switched in this PR:

  • Binomial: Alican
  • Multinomial: Alican
  • MultivariateNormal: Brooks
  • HalfCauchy: JP
  • Poisson: Rachit
  • LogNormal: Fritz
  • Delta: may not need a PyTorch wrapper at all

@martinjankowiak
Copy link
Copy Markdown
Collaborator

congrats to everyone who put in the hardwork to make this happen!

@neerajprad
Copy link
Copy Markdown
Member

neerajprad commented Jan 12, 2018

There was some AWS_KEY in the env that was messing up the S3 download. I removed that and restarted the tests.

@fritzo
Copy link
Copy Markdown
Member Author

fritzo commented Jan 12, 2018

@null-a Would you mind taking a look at the error in air? It looks like batch_size semantics may have changed, but I have been unable to pinpoint where the tensor of incorrect size torch.Size((50,)) is created.

This is the last remaining bug blocking us from switching to PyTorch distributions. I spent an hour or so last night trying to diagnose it, and I'd appreciate any help you could provide. Let me know if I can help you to reproduce the error.

Details
Traceback (most recent call last):
  File "/Users/fritzobermeyer/github/uber/pyro/examples/air/main.py", line 328, in <module>
    main(**vars(parser.parse_args()))
  File "/Users/fritzobermeyer/github/uber/pyro/examples/air/main.py", line 215, in main
    loss = svi.step(X, args.batch_size, z_pres_prior_p=partial(z_pres_prior_p, i))
  File "/Users/fritzobermeyer/github/uber/pyro/pyro/infer/svi.py", line 98, in step
    loss = self.loss_and_grads(self.model, self.guide, *args, **kwargs)
  File "/Users/fritzobermeyer/github/uber/pyro/pyro/infer/elbo.py", line 65, in loss_and_grads
    return self.which_elbo.loss_and_grads(model, guide, *args, **kwargs)
  File "/Users/fritzobermeyer/github/uber/pyro/pyro/infer/tracegraph_elbo.py", line 256, in loss_and_grads
    for weight, model_trace, guide_trace in self._get_traces(model, guide, *args, **kwargs):
  File "/Users/fritzobermeyer/github/uber/pyro/pyro/infer/tracegraph_elbo.py", line 211, in _get_traces
    check_model_guide_match(model_trace, guide_trace)
  File "/Users/fritzobermeyer/github/uber/pyro/pyro/util.py", line 363, in check_model_guide_match
    name, model_shape, guide_shape))
ValueError: Model and guide dims disagree at site 'z_what_2': torch.Size([50]) vs torch.Size([64, 50])

@null-a
Copy link
Copy Markdown
Collaborator

null-a commented Jan 12, 2018

Would you mind taking a look at the error in air?

@fritzo: Sure thing. Pointers as to how to reproduce would be helpful. I'm currently seeing the following error when I run examples/air/main.py:

    torch_dist = torch.distributions.Bernoulli(probs=ps, logits=logits)
TypeError: __init__() got an unexpected keyword argument 'logits'

That's with torch (0.3.0.post4).

@neerajprad
Copy link
Copy Markdown
Member

@null-a - Could you try testing with PyTorch master branch? The easiest way to build it would be to download the CPU wheels from s3://pyro-ppl/ci, and installing it via pip in a separate virtual environment. Or else you could simply follow the instructions on PyTorch's README.

# Install awscli first - https://docs.aws.amazon.com/cli/latest/userguide/installing.html
mkdir -p tmp
# python 2.7
aws s3 --no-sign-request sync s3://pyro-ppl/ci tmp --exclude "*" --include "*-cp27-p*"
# python 3.5  
aws s3 --no-sign-request sync s3://pyro-ppl/ci tmp --exclude "*" --include "*-cp35-*"  
pip install tmp/*
rm -r tmp

@null-a
Copy link
Copy Markdown
Collaborator

null-a commented Jan 12, 2018

Could you try testing with PyTorch master branch?

@neerajprad: Great, with that I'm seeing the error, thanks.

but I have been unable to pinpoint where the tensor of incorrect size torch.Size((50,)) is created.

@fritzo: If I apply this diff then examples/air/main.py runs OK. I'm not familiar with the recent changes, so I'm not sure if this is correct thing to do, but does that help?

@fritzo
Copy link
Copy Markdown
Member Author

fritzo commented Jan 12, 2018

Thanks @null-a, your fix looks like the right thing to do.

@null-a
Copy link
Copy Markdown
Collaborator

null-a commented Jan 12, 2018

@fritzo: Great. I guess there will need to be similar changes made to the AIR example notebook. I could take a look at that sometime, but I won't get to it today.

@neerajprad
Copy link
Copy Markdown
Member

@fritzo - Should we modify the notebooks as well, or get this merged as is?

@fritzo
Copy link
Copy Markdown
Member Author

fritzo commented Jan 13, 2018

I'd merge this as is. Authors of notebooks without unit tests are responsible for maintaining those notebooks by hand.

@fritzo
Copy link
Copy Markdown
Member Author

fritzo commented Jan 13, 2018

@neerajprad Ready to merge? I'm wrapping Alican's Multinomial on top of this PR.

@neerajprad neerajprad merged commit 57cf8dc into dev Jan 13, 2018
@neerajprad
Copy link
Copy Markdown
Member

Ready to merge? I'm wrapping Alican's Multinomial on top of this PR.

@fritzo - Merged. Could you merge dev into your Multinomial PR?

@null-a
Copy link
Copy Markdown
Collaborator

null-a commented Jan 13, 2018

Authors of notebooks without unit tests are responsible for maintaining those notebooks by hand.

@fritzo: Can you give me a pointer as to how I add unit tests for the AIR notebook. At the time I wrote this, I got the impression that basic checks for notebooks (that e.g. make sure they run without error) were in the works? I won't be manually checking the AIR notebook against every release, so without something like this it will rot.

@fritzo
Copy link
Copy Markdown
Member Author

fritzo commented Jan 13, 2018

@null-a Here's a possible way to test tutorials on CI: #678

@null-a null-a mentioned this pull request Jan 15, 2018
@fritzo fritzo deleted the wrap-torch-distributions branch February 3, 2018 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants