Skip to content

Fix lint formatting and mypy checks#3453

Merged
fritzo merged 18 commits into
devfrom
fix-gh-ci
Jun 5, 2026
Merged

Fix lint formatting and mypy checks#3453
fritzo merged 18 commits into
devfrom
fix-gh-ci

Conversation

@ordabayevy

@ordabayevy ordabayevy commented May 25, 2026

Copy link
Copy Markdown
Member

Main Changes

  • CI/tooling compatibility

    • Removed global CC=gcc-9 / CXX=g++-9 from GitHub Actions so PyTorch C++ extensions can use a newer runner compiler.
    • Added --warn-unused-ignores to make lint.
    • Updated mypy target from Python 3.9 to 3.10.
    • Disabled pytest-benchmark in test-funsor because it warns under xdist, and warnings are errors.
  • Dependency cleanup

    • Removed visdom from broad extras/test dependencies.
    • Made Visdom imports lazy in AIR/VAE examples, so CI can run examples without installing Visdom unless visualization flags are used.
    • Pinned funsor[torch] to the remote fixed commit in setup.py and docs/requirements.txt.
  • PyTorch compatibility fixes

    • Added Uniform.infer_shapes() to avoid newer Torch’s property-backed arg_constraints issue.
    • Replaced list-based tensor indexing with tuple indexing in stable log-prob, stats, and DCT Adam code.
    • Removed the obsolete lazy_property.__call__ patch that was causing inspect/doctest issues with newer Torch.
  • Typing/lint cleanup

    • Removed stale type: ignore comments now caught by --warn-unused-ignores.
  • Other cleanup

    • Removed the optional gpytorch.lazy.NonLazyTensor path in SpanningTree.log_partition_function, using torch.linalg.cholesky directly.

Why

The branch mainly makes the project work with newer PyTorch/tooling: PyTorch changed arg_constraints, warns on list indexing and tensor scalar conversion, and now requires a newer C++ compiler path for extensions. It also reduces CI fragility by removing Visdom from the default test dependency set and tightening lint so stale ignores don’t accumulate.

@fritzo

fritzo commented May 25, 2026

Copy link
Copy Markdown
Member

Thank you, Yerdos!

Preinstall visdom without build isolation to avoid pkg_resources failures on modern setuptools, require explicit context in ConditionalAutoRegressiveNN, and replace cast-based mypy suppressions with type ignores.
@martinjankowiak

Copy link
Copy Markdown
Collaborator

@ordabayevy thanks! what else needs to be done here to merge?

@ordabayevy

Copy link
Copy Markdown
Member Author

There are unit tests that are failing due to the new PyTorch version. I will try to get them fixed today.

@ordabayevy ordabayevy left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fritzo @martinjankowiak ready for a review!

Comment thread .github/workflows/ci.yml
run: |
python -m pip install --upgrade pip wheel setuptools
pip install ruff black mypy nbstripout nbformat
pip install -e .

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this so that the type checker can get dependency libraries stubs.

Comment thread docs/requirements.txt
pyro-api>=0.1.1
tqdm>=4.36
funsor[torch]
funsor[torch] @ git+https://github.com/pyro-ppl/funsor.git@8a8ca81fcc61733ad82e163028c7ff78420df9f0

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be pinned to a released funsor version before pyro release.

Comment thread examples/air/main.py

# Viz sample from prior.
if args.viz:
import visdom

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visdom is not actively supported - made the import lazy.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just replace this with some matplotlib equivalent?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In another PR? This one already has a lot of changes

Comment thread examples/baseball.py
test_data = torch.tensor(
pd_dataframe[["SeasonAt-Bats", "SeasonHits"]].values,
dtype=torch.float,
device=device,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor should use the default device so no need to pass it.

permutation = torch.randperm(channels, device="cpu").to(
torch.Tensor().device
)
permutation = torch.randperm(channels)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems redundant.

log_det = gpytorch.lazy.NonLazyTensor(truncated).logdet()
except ImportError:
log_det = torch.linalg.cholesky(truncated).diag().log().sum() * 2
log_det = torch.linalg.cholesky(truncated).diag().log().sum() * 2

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NonLazyTensor doesn't exist in new gpytorch releases.

def integrate(fn, domain):
sl = [slice(None)] + (len(domain.shape) - 1) * [None]
half_roots_sl = half_roots[sl]
half_roots_sl = half_roots[tuple(sl)]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In new pytorch releases list of tensors index gets wrapped in torch.tensor().


@staticmethod
def infer_shapes(low, high):
return torch.Size(broadcast_shape(low, high)), torch.Size()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superclass infer_shapes relies on cls.arg_constraints but in new pytorch Uniform.arg_constraints became an instance property.

assert chain_id < self.num_chains
self.exec_traces.append(tr)
self.log_weights.append(logit)
self.log_weights.append(torch.as_tensor(logit).detach())

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old torch.tensor(self.log_weights) would remove grads and emit warning so detaching here should be okay?

alpha_atol = 0.1 if alpha_near_one else 0.04
beta_atol = 0.12 if alpha_near_one else 0.06
assert_close(alpha, pyro.param("alpha").item(), atol=alpha_atol)
assert_close(beta, pyro.param("beta").item(), atol=beta_atol)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to increase tolerance for tests to pass.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because of your precision change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so because torch.as_tensor should return double but I'm re-running the stricter test with explicit double() to verify.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fails with explicit double() too

Comment thread examples/air/main.py

# Viz sample from prior.
if args.viz:
import visdom

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just replace this with some matplotlib equivalent?

Comment thread pyro/distributions/stable_log_prob.py Outdated
roots, weights = roots_legendre(num_points)
roots = torch.Tensor(roots).double()
weights = torch.Tensor(weights).double()
roots = torch.as_tensor(roots)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep doouble?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roots_legendre returns float64 and torch.as_tensor preserves the double dtype.

alpha_atol = 0.1 if alpha_near_one else 0.04
beta_atol = 0.12 if alpha_near_one else 0.06
assert_close(alpha, pyro.param("alpha").item(), atol=alpha_atol)
assert_close(beta, pyro.param("beta").item(), atol=beta_atol)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because of your precision change?

@ordabayevy

Copy link
Copy Markdown
Member Author

I don't remember having the DCO check before. Was it enabled automatically? Do I have to sign and push a commit?

@martinjankowiak

Copy link
Copy Markdown
Collaborator

not sure about DCO. but yeah try signing your commit...

Signed-off-by: Yerdos Ordabayev <yerdos2030@gmail.com>
@fritzo fritzo enabled auto-merge (squash) June 5, 2026 18:10
@fritzo fritzo merged commit 6cc3ecd into dev Jun 5, 2026
9 checks passed
@martinjankowiak

Copy link
Copy Markdown
Collaborator

thanks yerdos!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants