modernize, increase annotations, document - #1
Conversation
- more type annotations. - replace common functions with torch_einops_kit. - hunterMakesPy.raiseIfNone for type narrowing. - some formatting. - change flow to deduplicate. - change assert to raise and improve messages. - Remove inline comments from Captain Obvious. - use class attributes instead of initialization parameters. - prevent corner-case error with a warning. - remove unnecessary check.
hunterhogan
left a comment
There was a problem hiding this comment.
I need type annotations and documentation. I wish I had noticed your PR before I had typed the entire module. I plan to publish a typed and documented version because I use it in another package I will soon publish.
On style
So I could match the style of lucidrains in my pull requests, https://github.com/lucidrains/torch-einops-utils/pulls, I anaylzed his repos and created:
ruff.toml à la lucidrains
extend = "pyproject.toml"
line-length = 187
[lint]
select = ["ALL"]
ignore = [
"C901",
"COM812",
"D",
"E402",
"E701",
"E722",
"E731",
"E741",
"FBT001",
"FBT002",
"FBT003",
"FIX",
"I",
"N812",
"PLR0913",
"Q000",
"S301",
"SIM108",
"SIM300",
"T201",
"TC",
"TD",
]
[lint.per-file-ignores]
"tests/**.py" = [
"S101",
"FBT001",
]
[lint.flake8-import-conventions.aliases]
"accelerate.utils.dataclasses" = "accelerate_dataclasses"
"bidirectional_cross_attention.BidirectionalCrossAttentionTransformer" = "BiCrossAttnTransformer"
"einops.layers.torch.EinMix" = "Mix"
"hyper_connections.manifold_constrained_hyper_connections.get_expand_reduce_stream_functions" = "mc_get_expand_reduce_stream_functions"
"jax.numpy" = "jnp"
"kornia.augmentation" = "augs"
"torch.autograd.grad" = "torch_grad"
"torch.nn.functional" = "F"
"torch.nn.parallel.DistributedDataParallel" = "DDP"
"torchvision.transforms" = "T"
[format]
docstring-code-format = true
quote-style = "single"My style
My style is quite different and idiosyncratic. I've "codified" it in the five configuration files in https://github.com/hunterhogan/hunterMakesPy. ("Codified" is a legal term: I can't think of the programming term right now.)
Our style?
If you want to collaborate on this package, we can pick a style that suits us. I don't think lucidraids will merge your PR "tomorrow", so we may as well code in our own style.
Docstrings are next
I've drafted docstrings. I need to do another round of editing, though.
Coincidentally, I grew up in Houston. I went to high school out by 1960 and 45.
|
I'm all but certain that the docstrings need revision. I hope, however, they are 1. better than nothing and 2. easier for an expert to fix than for an expert to write from scratch. |
hunterhogan
left a comment
There was a problem hiding this comment.
IDK what to do with this PR, so I'm not doing anything right now.
No description provided.