botorch dynamo errors
Labels: triaged, oncall: pt2

botorch is a library for bayesian optimization in pytorch https://github.com/pytorch/botorch

`pip install botorch`

## Repro


```python
import torch
from botorch.models import SingleTaskGP
from botorch.fit import fit_gpytorch_model
from botorch.utils import standardize
from gpytorch.mlls import ExactMarginalLogLikelihood
import torchdynamo

train_X = torch.rand(10, 2)
Y = 1 - torch.norm(train_X - 0.5, dim=-1, keepdim=True)
Y = Y + 0.1 * torch.randn_like(Y)  # add some noise
train_Y = standardize(Y)

gp = SingleTaskGP(train_X, train_Y)
mll = ExactMarginalLogLikelihood(gp.likelihood, gp)

with torchdynamo.optimize("eager"):
    model = fit_gpytorch_model(mll)
print(model)
```

## Logs without torchdynamo

```
ExactMarginalLogLikelihood(
  (likelihood): GaussianLikelihood(
    (noise_covar): HomoskedasticNoise(
      (noise_prior): GammaPrior()
      (raw_noise_constraint): GreaterThan(1.000E-04)
    )
  )
  (model): SingleTaskGP(
    (likelihood): GaussianLikelihood(
      (noise_covar): HomoskedasticNoise(
        (noise_prior): GammaPrior()
        (raw_noise_constraint): GreaterThan(1.000E-04)
      )
    )
    (mean_module): ConstantMean()
    (covar_module): ScaleKernel(
      (base_kernel): MaternKernel(
        (lengthscale_prior): GammaPrior()
        (raw_lengthscale_constraint): Positive()
        (distance_module): Distance()
      )
      (outputscale_prior): GammaPrior()
      (raw_outputscale_constraint): Positive()
    )
  )
)
```

## Logs with torchdynamo

```
(myenv) ubuntu@ip-172-31-21-78:~/tests$ python bo.py 
Traceback (most recent call last):
  File "bo.py", line 17, in <module>
    model = fit_gpytorch_model(mll)
  File "/home/ubuntu/.conda/envs/myenv/lib/python3.8/site-packages/botorch/fit.py", line 38, in fit_gpytorch_model
    def fit_gpytorch_model(
  File "/home/ubuntu/.conda/envs/myenv/lib/python3.8/site-packages/botorch/fit.py", line 38, in fit_gpytorch_model
    def fit_gpytorch_model(
  File "/home/ubuntu/.conda/envs/myenv/lib/python3.8/site-packages/botorch/fit.py", line 38, in fit_gpytorch_model
    def fit_gpytorch_model(
  File "/home/ubuntu/.conda/envs/myenv/lib/python3.8/site-packages/botorch/fit.py", line 130, in fit_gpytorch_model
    mll, _ = optimizer(mll, track_iterations=False, **kwargs)
  File "/home/ubuntu/.conda/envs/myenv/lib/python3.8/site-packages/botorch/optim/fit.py", line 174, in fit_gpytorch_scipy
    def fit_gpytorch_scipy(
  File "/home/ubuntu/.conda/envs/myenv/lib/python3.8/site-packages/botorch/optim/fit.py", line 174, in fit_gpytorch_scipy
    def fit_gpytorch_scipy(
  File "/home/ubuntu/.conda/envs/myenv/lib/python3.8/site-packages/botorch/optim/fit.py", line 239, in fit_gpytorch_scipy
    res = minimize(
  File "/home/ubuntu/.conda/envs/myenv/lib/python3.8/site-packages/scipy/optimize/_minimize.py", line 45, in minimize
    def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
  File "/home/ubuntu/.conda/envs/myenv/lib/python3.8/site-packages/scipy/optimize/_minimize.py", line 45, in minimize
    def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
  File "/home/ubuntu/.conda/envs/myenv/lib/python3.8/site-packages/scipy/optimize/_minimize.py", line 699, in minimize
    res = _minimize_lbfgsb(fun, x0, args, jac, bounds,
  File "/home/ubuntu/.conda/envs/myenv/lib/python3.8/site-packages/scipy/optimize/_lbfgsb_py.py", line 212, in _minimize_lbfgsb
    def _minimize_lbfgsb(fun, x0, args=(), jac=None, bounds=None,
  File "/home/ubuntu/.conda/envs/myenv/lib/python3.8/site-packages/scipy/optimize/_lbfgsb_py.py", line 212, in _minimize_lbfgsb
    def _minimize_lbfgsb(fun, x0, args=(), jac=None, bounds=None,
NameError: name 'torch' is not defined
```

But I do have `torch` installed and it does run just fine without dynamo

```
(myenv) ubuntu@ip-172-31-21-78:~/tests$ pip list
Package             Version     Editable project location
------------------- ----------- -------------------------
attrs               22.1.0
black               22.6.0
botorch             0.6.6
certifi             2022.6.15
charset-normalizer  2.1.0
click               8.1.3
coolname            1.1.0
docstring-parser    0.14.1
expecttest          0.1.3
flake8              4.0.1
gpytorch            1.8.1
idna                3.3
importlib-metadata  4.12.0
importlib-resources 5.9.0
iniconfig           1.1.1
isort               5.10.1
Jinja2              3.1.2
joblib              1.1.0
jsonschema          4.7.2
MarkupSafe          2.1.1
mccabe              0.6.1
mosaicml            0.9.0
mpmath              1.2.1
multipledispatch    0.6.0
mypy-extensions     0.4.3
networkx            2.8.5
ninja               1.10.2.3
numpy               1.22.4
opt-einsum          3.3.0
packaging           21.3
pathspec            0.9.0
Pillow              9.2.0
pip                 22.2.2
platformdirs        2.5.2
pluggy              1.0.0
psutil              5.9.1
py                  1.11.0
py-cpuinfo          8.0.0
pycodestyle         2.8.0
pyDeprecate         0.3.2
pyflakes            2.4.0
pyparsing           3.0.9
pyro-api            0.1.2
pyro-ppl            1.8.1
pyrsistent          0.18.1
pytest              7.1.2
pytorch-ranger      0.1.1
PyYAML              6.0
requests            2.28.1
ruamel.yaml         0.17.21
ruamel.yaml.clib    0.2.6
scikit-learn        1.1.2
scipy               1.9.0
setuptools          65.0.2
six                 1.16.0
sympy               1.10.1
tabulate            0.8.9
threadpoolctl       3.1.0
tomli               2.0.1
torch               1.12.1
torch-optimizer     0.1.0
torchdynamo         1.13.0.dev0 /home/ubuntu/torchdynamo
torchmetrics        0.7.3
torchvision         0.13.1
tqdm                4.64.0
typing_extensions   4.3.0
urllib3             1.26.11
wheel               0.37.1
yahp                0.1.3
zipp                3.8.1
```

cc @ezyang @soumith @wconstab @ngimel @bdhirsh