repo stringlengths 7 90 | file_url stringlengths 81 315 | file_path stringlengths 4 228 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 14:38:15 2026-01-05 02:33:18 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/models/_registry.py | timm/models/_registry.py | """ Model Registry
Hacked together by / Copyright 2020 Ross Wightman
"""
import fnmatch
import re
import sys
import warnings
from collections import defaultdict, deque
from copy import deepcopy
from dataclasses import replace
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Sequence, Union, Tuple... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/models/swin_transformer_v2_cr.py | timm/models/swin_transformer_v2_cr.py | """ Swin Transformer V2
A PyTorch impl of : `Swin Transformer V2: Scaling Up Capacity and Resolution`
- https://arxiv.org/pdf/2111.09883
Code adapted from https://github.com/ChristophReich1996/Swin-Transformer-V2, original copyright/license info below
This implementation is experimental and subject to change in ... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | true |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/models/regnet.py | timm/models/regnet.py | """RegNet X, Y, Z, and more
Paper: `Designing Network Design Spaces` - https://arxiv.org/abs/2003.13678
Original Impl: https://github.com/facebookresearch/pycls/blob/master/pycls/models/regnet.py
Paper: `Fast and Accurate Model Scaling` - https://arxiv.org/abs/2103.06877
Original Impl: None
Based on original PyTorch... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | true |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/models/tresnet.py | timm/models/tresnet.py | """
TResNet: High Performance GPU-Dedicated Architecture
https://arxiv.org/pdf/2003.13630.pdf
Original model: https://github.com/mrT23/TResNet
"""
from collections import OrderedDict
from functools import partial
from typing import List, Optional, Tuple, Union, Type
import torch
import torch.nn as nn
from timm.laye... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/models/sknet.py | timm/models/sknet.py | """ Selective Kernel Networks (ResNet base)
Paper: Selective Kernel Networks (https://arxiv.org/abs/1903.06586)
This was inspired by reading 'Compounding the Performance Improvements...' (https://arxiv.org/abs/2001.06268)
and a streamlined impl at https://github.com/clovaai/assembled-cnn but I ended up building somet... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/models/densenet.py | timm/models/densenet.py | """Pytorch Densenet implementation w/ tweaks
This file is a copy of https://github.com/pytorch/vision 'densenet.py' (BSD-3-Clause) with
fixed kwargs passthrough and addition of dynamic global avg/max pool.
"""
import re
from collections import OrderedDict
from typing import Any, Dict, Optional, Tuple, Type, Union
impo... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/models/features.py | timm/models/features.py | from ._features import *
import warnings
warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.models", FutureWarning)
| python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/models/res2net.py | timm/models/res2net.py | """ Res2Net and Res2NeXt
Adapted from Official Pytorch impl at: https://github.com/gasvn/Res2Net/
Paper: `Res2Net: A New Multi-scale Backbone Architecture` - https://arxiv.org/abs/1904.01169
"""
import math
from typing import Optional, Type
import torch
import torch.nn as nn
from timm.data import IMAGENET_DEFAULT_MEA... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/models/efficientvit_mit.py | timm/models/efficientvit_mit.py | """ EfficientViT (by MIT Song Han's Lab)
Paper: `Efficientvit: Enhanced linear attention for high-resolution low-computation visual recognition`
- https://arxiv.org/abs/2205.14756
Adapted from official impl at https://github.com/mit-han-lab/efficientvit
"""
__all__ = ['EfficientVit', 'EfficientVitLarge']
from ty... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | true |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/models/pvt_v2.py | timm/models/pvt_v2.py | """ Pyramid Vision Transformer v2
@misc{wang2021pvtv2,
title={PVTv2: Improved Baselines with Pyramid Vision Transformer},
author={Wenhai Wang and Enze Xie and Xiang Li and Deng-Ping Fan and Kaitao Song and Ding Liang and
Tong Lu and Ping Luo and Ling Shao},
year={2021},
eprint={2106.137... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/models/_hub.py | timm/models/_hub.py | import hashlib
import json
import logging
import os
from functools import partial
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
import torch
from torch.hub import HASH_REGEX, download_url_to_file, urlparse
try:
from torch.hub ... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/models/rdnet.py | timm/models/rdnet.py | """
RDNet
Copyright (c) 2024-present NAVER Cloud Corp.
Apache-2.0
"""
from functools import partial
from typing import List, Optional, Tuple, Union, Callable, Type
import torch
import torch.nn as nn
from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
from timm.layers import DropPath, calculate_drop_pat... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/models/hub.py | timm/models/hub.py | from ._hub import *
import warnings
warnings.warn(f"Importing from {__name__} is deprecated, please import via timm.models", FutureWarning)
| python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/models/layers/__init__.py | timm/models/layers/__init__.py | # NOTE timm.models.layers is DEPRECATED, please use timm.layers, this is here to reduce breakages in transition
from timm.layers.activations import *
from timm.layers.adaptive_avgmax_pool import \
adaptive_avgmax_pool2d, select_adaptive_pool2d, AdaptiveAvgMaxPool2d, SelectAdaptivePool2d
from timm.layers.attention_p... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/laprop.py | timm/optim/laprop.py | """ PyTorch impl of LaProp optimizer
Code simplified from https://github.com/Z-T-WANG/LaProp-Optimizer, MIT License
Paper: LaProp: Separating Momentum and Adaptivity in Adam, https://arxiv.org/abs/2002.04839
@article{ziyin2020laprop,
title={LaProp: a Better Way to Combine Momentum with Adaptive Gradient},
author... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/nvnovograd.py | timm/optim/nvnovograd.py | """ Nvidia NovoGrad Optimizer.
Original impl by Nvidia from Jasper example:
- https://github.com/NVIDIA/DeepLearningExamples/blob/master/PyTorch/SpeechRecognition/Jasper
Paper: `Stochastic Gradient Methods with Layer-wise Adaptive Moments for Training of Deep Networks`
- https://arxiv.org/abs/1905.11286
"""
im... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/adafactor_bv.py | timm/optim/adafactor_bv.py | """ Adafactor (Big Vision variant) for PyTorch
Adapted from the implementation in big vision: https://github.com/google-research/big_vision
Described in 'Scaling Vision Transformers': https://arxiv.org/abs/2106.04560
References for added functionality:
Cautious Optimizers: https://arxiv.org/abs/2411.16085
Wh... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/sgdp.py | timm/optim/sgdp.py | """
SGDP Optimizer Implementation copied from https://github.com/clovaai/AdamP/blob/master/adamp/sgdp.py
Paper: `Slowing Down the Weight Norm Increase in Momentum-based Optimizers` - https://arxiv.org/abs/2006.08217
Code: https://github.com/clovaai/AdamP
Copyright (c) 2020-present NAVER Corp.
MIT license
"""
import ... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/radam.py | timm/optim/radam.py | """RAdam Optimizer.
Implementation lifted from: https://github.com/LiyuanLucasLiu/RAdam
Paper: `On the Variance of the Adaptive Learning Rate and Beyond` - https://arxiv.org/abs/1908.03265
NOTE: This impl has been deprecated in favour of torch.optim.RAdam and remains as a reference
"""
import math
import torch
from to... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/adopt.py | timm/optim/adopt.py | """ ADOPT PyTorch Optimizer
ADOPT: Modified Adam Can Converge with Any β2 with the Optimal Rate: https://arxiv.org/abs/2411.02853
Modified for reduced dependencies on PyTorch internals from original at: https://github.com/iShohei220/adopt
@inproceedings{taniguchi2024adopt,
author={Taniguchi, Shohei and Harada, Keno... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/mars.py | timm/optim/mars.py | """ PyTorch MARS Optimizer
Code simplified from https://github.com/AGI-Arena/MARS
Paper: MARS: Unleashing the Power of Variance Reduction for Training Large Models - https://arxiv.org/abs/2411.10438
@article{yuan2024mars,
title={MARS: Unleashing the Power of Variance Reduction for Training Large Models},
author=... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/optim_factory.py | timm/optim/optim_factory.py | # lots of uses of these functions directly, ala 'import timm.optim.optim_factory as optim_factory', fun :/
from ._optim_factory import create_optimizer, create_optimizer_v2, optimizer_kwargs
from ._param_groups import param_groups_layer_decay, param_groups_weight_decay, group_parameters, _layer_map, _group
import war... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/muon.py | timm/optim/muon.py | """ Muon Optimizer
Improved Muon optimizer implementation with flexible handling of high-dimensional tensors.
Combines PyTorch-style structure with options for:
- Batched spatial processing for convolutions in addition to flatten
- Optional spatial normalization
- Selectable coefficient presets
- Automatic fallback t... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | true |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/sgdw.py | timm/optim/sgdw.py | """ SGD with decoupled weight-decay.
References for added functionality:
Cautious Optimizers: https://arxiv.org/abs/2411.16085
Why Gradients Rapidly Increase Near the End of Training: https://arxiv.org/abs/2506.02285
Hacked together by Ross Wightman
"""
from typing import List, Optional
import torch
from tor... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/adamw.py | timm/optim/adamw.py | """ AdamW Optimizer
Impl copied from PyTorch master
References for added functionality:
Cautious Optimizers: https://arxiv.org/abs/2411.16085
Why Gradients Rapidly Increase Near the End of Training: https://arxiv.org/abs/2506.02285
NOTE: This impl has been deprecated in favour of torch.optim.AdamW and remains... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/madgrad.py | timm/optim/madgrad.py | """ PyTorch MADGRAD optimizer
MADGRAD: https://arxiv.org/abs/2101.11075
Code from: https://github.com/facebookresearch/madgrad
"""
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import ma... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/_types.py | timm/optim/_types.py | from typing import Any, Dict, Iterable, Union, Protocol, Type
try:
from typing import TypeAlias
except ImportError:
from typing_extensions import TypeAlias
try:
from typing import TypeVar
except ImportError:
from typing_extensions import TypeVar
import torch
import torch.optim
try:
from torch.opti... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/nadamw.py | timm/optim/nadamw.py | """ NAdamW Optimizer
Based on simplified algorithm in https://github.com/mlcommons/algorithmic-efficiency/tree/main/baselines/nadamw
Added multi-tensor (foreach) path.
References for added functionality:
Cautious Optimizers: https://arxiv.org/abs/2411.16085
Why Gradients Rapidly Increase Near the End of Trai... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/_optim_factory.py | timm/optim/_optim_factory.py | """ Optimizer Factory w/ custom Weight Decay & Layer Decay support
Hacked together by / Copyright 2021 Ross Wightman
"""
import logging
from dataclasses import dataclass
from functools import partial
from typing import Any, Callable, Collection, Dict, List, Optional, Set, Tuple, Type, Union
from fnmatch import fnmatch... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | true |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/kron.py | timm/optim/kron.py | """ PyTorch Implementation of the Kron (PSGD) optimizer
This is a PSGD optimizer using a Kronecker-factored preconditioner.
This impl was adapted from https://github.com/evanatyourservice/kron_torch
by Evan Walters, licensed CC-BY-4.0.
Contributions to above also made by
* Lucas Nestler, added to his https://github.... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/lars.py | timm/optim/lars.py | """ PyTorch LARS / LARC Optimizer
An implementation of LARS (SGD) + LARC in PyTorch
Based on:
* PyTorch SGD: https://github.com/pytorch/pytorch/blob/1.7/torch/optim/sgd.py#L100
* NVIDIA APEX LARC: https://github.com/NVIDIA/apex/blob/master/apex/parallel/LARC.py
Additional cleanup and modifications to properly su... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/adabelief.py | timm/optim/adabelief.py | import math
import torch
from torch.optim.optimizer import Optimizer
class AdaBelief(Optimizer):
r"""Implements AdaBelief algorithm. Modified from Adam in PyTorch
Arguments:
params (iterable): iterable of parameters to optimize or dicts defining
parameter groups
lr (float, optiona... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/nadam.py | timm/optim/nadam.py | import math
import torch
from torch.optim.optimizer import Optimizer
class NAdamLegacy(Optimizer):
"""Implements Nadam algorithm (a variant of Adam based on Nesterov momentum).
NOTE: This impl has been deprecated in favour of torch.optim.NAdam and remains as a reference
It has been proposed in `Incorpo... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/lion.py | timm/optim/lion.py | """ Lion Optimizer
Paper: `Symbolic Discovery of Optimization Algorithms` - https://arxiv.org/abs/2302.06675
Original Impl: https://github.com/google/automl/tree/master/lion
References for added functionality:
Cautious Optimizers: https://arxiv.org/abs/2411.16085
Why Gradients Rapidly Increase Near the End of ... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/adan.py | timm/optim/adan.py | """ Adan Optimizer
Adan: Adaptive Nesterov Momentum Algorithm for Faster Optimizing Deep Models[J]. arXiv preprint arXiv:2208.06677, 2022.
https://arxiv.org/abs/2208.06677
Implementation adapted from https://github.com/sail-sg/Adan
"""
# Copyright 2022 Garena Online Private Limited
#
# Licensed under the Apache L... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/adahessian.py | timm/optim/adahessian.py | """ AdaHessian Optimizer
Lifted from https://github.com/davda54/ada-hessian/blob/master/ada_hessian.py
Originally licensed MIT, Copyright 2020, David Samuel
"""
import torch
class Adahessian(torch.optim.Optimizer):
"""
Implements the AdaHessian algorithm from "ADAHESSIAN: An Adaptive Second OrderOptimizer fo... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/__init__.py | timm/optim/__init__.py | from .adabelief import AdaBelief
from .adafactor import Adafactor
from .adafactor_bv import AdafactorBigVision
from .adahessian import Adahessian
from .adamp import AdamP
from .adamw import AdamWLegacy
from .adan import Adan
from .adopt import Adopt
from .lamb import Lamb
from .laprop import LaProp
from .lars import La... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/_param_groups.py | timm/optim/_param_groups.py | import fnmatch
import logging
from itertools import islice
from typing import Collection, Optional
from torch import nn as nn
from timm.models import group_parameters
_logger = logging.getLogger(__name__)
def _matches_pattern(name: str, patterns: Collection[str]) -> bool:
"""Check if parameter name matches an... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/lookahead.py | timm/optim/lookahead.py | """ Lookahead Optimizer Wrapper.
Implementation modified from: https://github.com/alphadl/lookahead.pytorch
Paper: `Lookahead Optimizer: k steps forward, 1 step back` - https://arxiv.org/abs/1907.08610
Hacked together by / Copyright 2020 Ross Wightman
"""
from collections import OrderedDict
from typing import Callable... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/rmsprop_tf.py | timm/optim/rmsprop_tf.py | """ RMSProp modified to behave like Tensorflow impl
Originally cut & paste from PyTorch RMSProp
https://github.com/pytorch/pytorch/blob/063946d2b3f3f1e953a2a3b54e0b34f1393de295/torch/optim/rmsprop.py
Licensed under BSD-Clause 3 (ish), https://github.com/pytorch/pytorch/blob/master/LICENSE
References for added functio... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/adafactor.py | timm/optim/adafactor.py | """ Adafactor Optimizer
Lifted from https://github.com/pytorch/fairseq/blob/master/fairseq/optim/adafactor.py
Modified by Ross Wightman to fix some issues with factorization dims for non nn.Linear layers
Original header/copyright below.
"""
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is l... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/adamp.py | timm/optim/adamp.py | """
AdamP Optimizer Implementation copied from https://github.com/clovaai/AdamP/blob/master/adamp/adamp.py
Paper: `Slowing Down the Weight Norm Increase in Momentum-based Optimizers` - https://arxiv.org/abs/2006.08217
Code: https://github.com/clovaai/AdamP
Copyright (c) 2020-present NAVER Corp.
MIT license
"""
impor... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/optim/lamb.py | timm/optim/lamb.py | """ PyTorch Lamb optimizer w/ behaviour similar to NVIDIA FusedLamb
This optimizer code was adapted from the following (starting with latest)
* https://github.com/HabanaAI/Model-References/blob/2b435114fe8e31f159b1d3063b8280ae37af7423/PyTorch/nlp/bert/pretraining/lamb.py
* https://github.com/NVIDIA/DeepLearningExample... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/cuda.py | timm/utils/cuda.py | """ CUDA / AMP utils
Hacked together by / Copyright 2020 Ross Wightman
"""
import torch
try:
from apex import amp
has_apex = True
except ImportError:
amp = None
has_apex = False
from .clip_grad import dispatch_clip_grad
class ApexScaler:
state_dict_key = "amp"
def __call__(
sel... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/metrics.py | timm/utils/metrics.py | """ Eval metrics and related
Hacked together by / Copyright 2020 Ross Wightman
"""
class AverageMeter:
"""Computes and stores the average and current value"""
def __init__(self):
self.reset()
def reset(self):
self.val = 0
self.avg = 0
self.sum = 0
self.count = 0
... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/model_ema.py | timm/utils/model_ema.py | """ Exponential Moving Average (EMA) of model updates
Hacked together by / Copyright 2020 Ross Wightman
"""
import logging
from collections import OrderedDict
from copy import deepcopy
from typing import Optional
import torch
import torch.nn as nn
_logger = logging.getLogger(__name__)
class ModelEma:
""" Model... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/attention_extract.py | timm/utils/attention_extract.py | import fnmatch
import re
from collections import OrderedDict
from typing import Union, Optional, List
import torch
class AttentionExtract(torch.nn.Module):
# defaults should cover a significant number of timm models with attention maps.
default_node_names = ['*attn.softmax']
default_module_names = ['*att... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/model.py | timm/utils/model.py | """ Model / state_dict utils
Hacked together by / Copyright 2020 Ross Wightman
"""
import fnmatch
from copy import deepcopy
import torch
from torchvision.ops.misc import FrozenBatchNorm2d
from timm.layers import BatchNormAct2d, SyncBatchNormAct, FrozenBatchNormAct2d,\
freeze_batch_norm_2d, unfreeze_batch_norm_2d... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/clip_grad.py | timm/utils/clip_grad.py | import torch
from timm.utils.agc import adaptive_clip_grad
def dispatch_clip_grad(parameters, value: float, mode: str = 'norm', norm_type: float = 2.0):
""" Dispatch to gradient clipping method
Args:
parameters (Iterable): model parameters to clip
value (float): clipping value/factor/norm, m... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/summary.py | timm/utils/summary.py | """ Summary utilities
Hacked together by / Copyright 2020 Ross Wightman
"""
import csv
import os
from collections import OrderedDict
try:
import wandb
except ImportError:
pass
def get_outdir(path, *paths, inc=False):
outdir = os.path.join(path, *paths)
if not os.path.exists(outdir):
os.maked... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/checkpoint_saver.py | timm/utils/checkpoint_saver.py | """ Checkpoint Saver
Track top-n training checkpoints and maintain recovery checkpoints on specified intervals.
Hacked together by / Copyright 2020 Ross Wightman
"""
import glob
import logging
import operator
import os
import shutil
import torch
from .model import unwrap_model, get_state_dict
_logger = logging.g... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/log.py | timm/utils/log.py | """ Logging helpers
Hacked together by / Copyright 2020 Ross Wightman
"""
import logging
import logging.handlers
class FormatterNoInfo(logging.Formatter):
def __init__(self, fmt='%(levelname)s: %(message)s'):
logging.Formatter.__init__(self, fmt)
def format(self, record):
if record.levelno =... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/jit.py | timm/utils/jit.py | """ JIT scripting/tracing utils
Hacked together by / Copyright 2020 Ross Wightman
"""
import os
import torch
def set_jit_legacy():
""" Set JIT executor to legacy w/ support for op fusion
This is hopefully a temporary need in 1.5/1.5.1/1.6 to restore performance due to changes
in the JIT executor. These ... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/distributed.py | timm/utils/distributed.py | """ Distributed training/validation utils
Hacked together by / Copyright 2020 Ross Wightman
"""
import logging
import os
from typing import Optional
import torch
from torch import distributed as dist
from .model import unwrap_model
_logger = logging.getLogger(__name__)
def reduce_tensor(tensor, n):
rt = tenso... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/misc.py | timm/utils/misc.py | """ Misc utils
Hacked together by / Copyright 2020 Ross Wightman
"""
import argparse
import ast
import re
def natural_key(string_):
"""See http://www.codinghorror.com/blog/archives/001018.html"""
return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', string_.lower())]
def add_bool_arg(parser, nam... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/random.py | timm/utils/random.py | import random
import numpy as np
import torch
def random_seed(seed=42, rank=0):
torch.manual_seed(seed + rank)
np.random.seed(seed + rank)
random.seed(seed + rank)
| python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/__init__.py | timm/utils/__init__.py | from .agc import adaptive_clip_grad
from .attention_extract import AttentionExtract
from .checkpoint_saver import CheckpointSaver
from .clip_grad import dispatch_clip_grad
from .cuda import ApexScaler, NativeScaler
from .decay_batch import decay_batch_step, check_batch_size_retry
from .distributed import distribute_bn,... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/decay_batch.py | timm/utils/decay_batch.py | """ Batch size decay and retry helpers.
Copyright 2022 Ross Wightman
"""
import math
def decay_batch_step(batch_size, num_intra_steps=2, no_odd=False):
""" power of two batch-size decay with intra steps
Decay by stepping between powers of 2:
* determine power-of-2 floor of current batch size (base batch... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/agc.py | timm/utils/agc.py | """ Adaptive Gradient Clipping
An impl of AGC, as per (https://arxiv.org/abs/2102.06171):
@article{brock2021high,
author={Andrew Brock and Soham De and Samuel L. Smith and Karen Simonyan},
title={High-Performance Large-Scale Image Recognition Without Normalization},
journal={arXiv preprint arXiv:},
year={2021... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/utils/onnx.py | timm/utils/onnx.py | from typing import Optional, Tuple, List
import torch
def onnx_forward(onnx_file, example_input):
import onnxruntime
sess_options = onnxruntime.SessionOptions()
session = onnxruntime.InferenceSession(onnx_file, sess_options)
input_name = session.get_inputs()[0].name
output = session.run([], {inp... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/scheduler/scheduler_factory.py | timm/scheduler/scheduler_factory.py | """ Scheduler Factory
Hacked together by / Copyright 2021 Ross Wightman
"""
from typing import List, Optional, Union
from torch.optim import Optimizer
from .cosine_lr import CosineLRScheduler
from .multistep_lr import MultiStepLRScheduler
from .plateau_lr import PlateauLRScheduler
from .poly_lr import PolyLRScheduler... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/scheduler/plateau_lr.py | timm/scheduler/plateau_lr.py | """ Plateau Scheduler
Adapts PyTorch plateau scheduler and allows application of noise, warmup.
Hacked together by / Copyright 2020 Ross Wightman
"""
import torch
from typing import Any, Dict, List, Optional, Tuple, Union
from .scheduler import Scheduler
class PlateauLRScheduler(Scheduler):
"""Decay the LR by ... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/scheduler/step_lr.py | timm/scheduler/step_lr.py | """ Step Scheduler
Basic step LR schedule with warmup, noise.
Hacked together by / Copyright 2020 Ross Wightman
"""
import math
import torch
from typing import List, Tuple, Union
from .scheduler import Scheduler
class StepLRScheduler(Scheduler):
"""
"""
def __init__(
self,
opt... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/scheduler/poly_lr.py | timm/scheduler/poly_lr.py | """ Polynomial Scheduler
Polynomial LR schedule with warmup, noise.
Hacked together by / Copyright 2021 Ross Wightman
"""
import math
import logging
from typing import List, Tuple, Union
import torch
from .scheduler import Scheduler
_logger = logging.getLogger(__name__)
class PolyLRScheduler(Scheduler):
"""... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/scheduler/multistep_lr.py | timm/scheduler/multistep_lr.py | """ MultiStep LR Scheduler
Basic multi step LR schedule with warmup, noise.
"""
import torch
import bisect
from timm.scheduler.scheduler import Scheduler
from typing import List, Tuple, Union
class MultiStepLRScheduler(Scheduler):
"""
"""
def __init__(
self,
optimizer: torch.optim... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/scheduler/__init__.py | timm/scheduler/__init__.py | from .cosine_lr import CosineLRScheduler
from .multistep_lr import MultiStepLRScheduler
from .plateau_lr import PlateauLRScheduler
from .poly_lr import PolyLRScheduler
from .step_lr import StepLRScheduler
from .tanh_lr import TanhLRScheduler
from .scheduler_factory import create_scheduler, create_scheduler_v2, schedul... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/scheduler/tanh_lr.py | timm/scheduler/tanh_lr.py | """ TanH Scheduler
TanH schedule with warmup, cycle/restarts, noise.
Hacked together by / Copyright 2021 Ross Wightman
"""
import logging
import math
import numpy as np
import torch
from typing import List, Tuple, Union
from .scheduler import Scheduler
_logger = logging.getLogger(__name__)
class TanhLRScheduler(... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/scheduler/scheduler.py | timm/scheduler/scheduler.py | import abc
from abc import ABC
from typing import Any, Dict, List, Optional, Tuple, Union
import torch
class Scheduler(ABC):
""" Parameter Scheduler Base Class
A scheduler base class that can be used to schedule any optimizer parameter groups.
Unlike the builtin PyTorch schedulers, this is intended to b... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/scheduler/cosine_lr.py | timm/scheduler/cosine_lr.py | """ Cosine Scheduler
Cosine LR schedule with warmup, cycle/restarts, noise, k-decay.
Hacked together by / Copyright 2021 Ross Wightman
"""
import logging
import math
import numpy as np
import torch
from typing import Tuple, List, Union
from .scheduler import Scheduler
_logger = logging.getLogger(__name__)
class ... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/format.py | timm/layers/format.py | from enum import Enum
from typing import Union
import torch
class Format(str, Enum):
NCHW = 'NCHW'
NHWC = 'NHWC'
NCL = 'NCL'
NLC = 'NLC'
FormatT = Union[str, Format]
def get_spatial_dim(fmt: FormatT):
"""Return spatial dimension indices for a given tensor format.
Args:
fmt: Tenso... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/gather_excite.py | timm/layers/gather_excite.py | """ Gather-Excite Attention Block
Paper: `Gather-Excite: Exploiting Feature Context in CNNs` - https://arxiv.org/abs/1810.12348
Official code here, but it's only partial impl in Caffe: https://github.com/hujie-frank/GENet
I've tried to support all of the extent both w/ and w/o params. I don't believe I've seen anoth... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/typing.py | timm/layers/typing.py | from contextlib import nullcontext
from functools import wraps
from typing import Callable, Optional, Tuple, Type, TypeVar, Union, overload, ContextManager
import torch
__all__ = ["LayerType", "PadType", "nullwrap", "disable_compiler"]
LayerType = Union[str, Callable, Type[torch.nn.Module]]
PadType = Union[str, int... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/patch_dropout.py | timm/layers/patch_dropout.py | from typing import Optional, Tuple, Union
import torch
import torch.nn as nn
def patch_dropout_forward(
x: torch.Tensor,
prob: float,
num_prefix_tokens: int,
ordered: bool,
training: bool,
) -> Tuple[torch.Tensor, Optional[torch.Tensor]]:
"""
Common forward logic for p... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/eca.py | timm/layers/eca.py | """
ECA module from ECAnet
paper: ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks
https://arxiv.org/abs/1910.03151
Original ECA model borrowed from https://github.com/BangguWu/ECANet
Modified circular ECA implementation and adaption for use in timm package
by Chris Ha https://github.com/V... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/test_time_pool.py | timm/layers/test_time_pool.py | """ Test Time Pooling (Average-Max Pool)
Hacked together by / Copyright 2020 Ross Wightman
"""
import logging
from torch import nn
import torch.nn.functional as F
from .adaptive_avgmax_pool import adaptive_avgmax_pool2d
_logger = logging.getLogger(__name__)
class TestTimePoolHead(nn.Module):
def __init__(sel... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/interpolate.py | timm/layers/interpolate.py | """ Interpolation helpers for timm layers
RegularGridInterpolator from https://github.com/sbarratt/torch_interpolations
Copyright Shane Barratt, Apache 2.0 license
"""
import torch
from itertools import product
class RegularGridInterpolator:
""" Interpolate data defined on a rectilinear grid with even or uneven ... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/halo_attn.py | timm/layers/halo_attn.py | """ Halo Self Attention
Paper: `Scaling Local Self-Attention for Parameter Efficient Visual Backbones`
- https://arxiv.org/abs/2103.12731
@misc{2103.12731,
Author = {Ashish Vaswani and Prajit Ramachandran and Aravind Srinivas and Niki Parmar and Blake Hechtman and
Jonathon Shlens},
Title = {Scaling Local Self... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/create_act.py | timm/layers/create_act.py | """ Activation Factory
Hacked together by / Copyright 2020 Ross Wightman
"""
from typing import Callable, Optional, Type, Union
from .activations import *
from .activations_me import *
from .config import is_exportable, is_scriptable
from .typing import LayerType
# PyTorch has an optimized, native 'silu' (aka 'swish'... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/weight_init.py | timm/layers/weight_init.py | import torch
import math
import warnings
from torch import nn
from torch.nn.init import _calculate_fan_in_and_fan_out
def is_meta_device(device) -> bool:
"""Check if targeting meta device (explicit arg or context manager)."""
if device is not None:
return str(device) == 'meta'
# Check context mana... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/attention_pool2d.py | timm/layers/attention_pool2d.py | """ Attention Pool 2D
Implementations of 2D spatial feature pooling using multi-head attention instead of average pool.
Based on idea in CLIP by OpenAI, licensed Apache 2.0
https://github.com/openai/CLIP/blob/3b473b0e682c091a9e53623eebc1ca1657385717/clip/model.py
Hacked together by / Copyright 2021 Ross Wightman
"""... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/filter_response_norm.py | timm/layers/filter_response_norm.py | """ Filter Response Norm in PyTorch
Based on `Filter Response Normalization Layer` - https://arxiv.org/abs/1911.09737
Hacked together by / Copyright 2021 Ross Wightman
"""
from typing import Optional, Type
import torch
import torch.nn as nn
from .create_act import create_act_layer
from .trace_utils import _assert
... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/activations_me.py | timm/layers/activations_me.py | """ Activations (memory-efficient w/ custom autograd)
A collection of activations fn and modules with a common interface so that they can
easily be swapped. All have an `inplace` arg even if not used.
These activations are not compatible with jit scripting or ONNX export of the model, please use
basic versions of the... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/squeeze_excite.py | timm/layers/squeeze_excite.py | """ Squeeze-and-Excitation Channel Attention
An SE implementation originally based on PyTorch SE-Net impl.
Has since evolved with additional functionality / configuration.
Paper: `Squeeze-and-Excitation Networks` - https://arxiv.org/abs/1709.01507
Also included is Effective Squeeze-Excitation (ESE).
Paper: `CenterMa... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/fast_norm.py | timm/layers/fast_norm.py | """ 'Fast' Normalization Functions
For GroupNorm and LayerNorm these functions bypass typical AMP upcast to float32.
Additionally, for LayerNorm, the APEX fused LN is used if available (which also does not upcast)
Hacked together by / Copyright 2022 Ross Wightman
"""
from typing import List, Optional
import torch
f... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/hybrid_embed.py | timm/layers/hybrid_embed.py | """ Image to Patch Hybird Embedding Layer
Hacked together by / Copyright 2020 Ross Wightman
"""
import logging
import math
from typing import List, Optional, Tuple, Union
import torch
from torch import nn as nn
import torch.nn.functional as F
from .format import Format, nchw_to
from .helpers import to_2tuple
from .p... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/create_norm_act.py | timm/layers/create_norm_act.py | """ NormAct (Normalization + Activation Layer) Factory
Create norm + act combo modules that attempt to be backwards compatible with separate norm + act
instances in models. Where these are used it will be possible to swap separate BN + act layers with
combined modules like IABN or EvoNorms.
Hacked together by / Copyr... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/norm_act.py | timm/layers/norm_act.py | """ Normalization + Activation Layers
Provides Norm+Act fns for standard PyTorch norm layers such as
* BatchNorm
* GroupNorm
* LayerNorm
This allows swapping with alternative layers that are natively both norm + act such as
* EvoNorm (evo_norm.py)
* FilterResponseNorm (filter_response_norm.py)
* InplaceABN (inplace_a... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/trace_utils.py | timm/layers/trace_utils.py | try:
from torch import _assert
except ImportError:
def _assert(condition: bool, message: str):
assert condition, message
def _float_to_int(x: float) -> int:
"""
Symbolic tracing helper to substitute for inbuilt `int`.
Hint: Inbuilt `int` can't accept an argument of type `Proxy`
"""
... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/bottleneck_attn.py | timm/layers/bottleneck_attn.py | """ Bottleneck Self Attention (Bottleneck Transformers)
Paper: `Bottleneck Transformers for Visual Recognition` - https://arxiv.org/abs/2101.11605
@misc{2101.11605,
Author = {Aravind Srinivas and Tsung-Yi Lin and Niki Parmar and Jonathon Shlens and Pieter Abbeel and Ashish Vaswani},
Title = {Bottleneck Transformers f... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/drop.py | timm/layers/drop.py | """ DropBlock, DropPath
PyTorch implementations of DropBlock and DropPath (Stochastic Depth) regularization layers.
Papers:
DropBlock: A regularization method for convolutional networks (https://arxiv.org/abs/1810.12890)
Deep Networks with Stochastic Depth (https://arxiv.org/abs/1603.09382)
Code:
DropBlock impl ins... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/pos_embed_rel.py | timm/layers/pos_embed_rel.py | """ Relative position embedding modules and functions
Hacked together by / Copyright 2022 Ross Wightman
"""
import math
import os
from typing import Optional, Tuple
import torch
import torch.nn as nn
import torch.nn.functional as F
from .grid import ndgrid
from .interpolate import RegularGridInterpolator
from .mlp i... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/pool1d.py | timm/layers/pool1d.py | import torch
def global_pool_nlc(
x: torch.Tensor,
pool_type: str = 'token',
num_prefix_tokens: int = 1,
reduce_include_prefix: bool = False,
):
"""Apply global pooling to tensor in NLC format.
Args:
x: Input tensor in (batch, length, channels) format.
pool_typ... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/pos_embed_sincos.py | timm/layers/pos_embed_sincos.py | """ Sin-cos, fourier, rotary position embedding modules and functions
Hacked together by / Copyright 2022 Ross Wightman
"""
import math
from typing import List, Tuple, Optional, Union
import torch
from torch import nn as nn
from ._fx import register_notrace_function
from .grid import ndgrid
from .trace_utils import ... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | true |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/non_local_attn.py | timm/layers/non_local_attn.py | """ Bilinear-Attention-Transform and Non-Local Attention
Paper: `Non-Local Neural Networks With Grouped Bilinear Attentional Transforms`
- https://openaccess.thecvf.com/content_CVPR_2020/html/Chi_Non-Local_Neural_Networks_With_Grouped_Bilinear_Attentional_Transforms_CVPR_2020_paper.html
Adapted from original code:... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/other_pool.py | timm/layers/other_pool.py | """ Non-Local Attention Pooling Layers
A collection of global pooling layers that go beyond simple avg/max pooling.
LSEPool - LogSumExp pooling, a smooth approximation between avg and max pooling
SimPool - Attention-based pooling from 'Keep It SimPool' (ICCV 2023)
Based on implementations from:
* LSE Pooling: custom... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/median_pool.py | timm/layers/median_pool.py | """ Median Pool
Hacked together by / Copyright 2020 Ross Wightman
"""
import torch.nn as nn
import torch.nn.functional as F
from .helpers import to_2tuple, to_4tuple
class MedianPool2d(nn.Module):
""" Median pool (usable as median filter when stride=1) module.
Args:
kernel_size: size of pooling kern... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/attention_pool.py | timm/layers/attention_pool.py | from typing import Optional, Type
import torch
import torch.nn as nn
import torch.nn.functional as F
from .attention import maybe_add_mask
from .config import use_fused_attn
from .mlp import Mlp
from .weight_init import trunc_normal_tf_
class AttentionPoolLatent(nn.Module):
""" Attention pooling w/ latent query... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/attention2d.py | timm/layers/attention2d.py | from typing import List, Optional, Type, Union
import torch
from torch import nn as nn
from torch.nn import functional as F
from .config import use_fused_attn
from .create_conv2d import create_conv2d
from .helpers import to_2tuple
from .pool2d_same import create_pool2d
class MultiQueryAttentionV2(nn.Module):
""... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/mlp.py | timm/layers/mlp.py | """ MLP module w/ dropout and configurable activation layer
Hacked together by / Copyright 2020 Ross Wightman
"""
from functools import partial
from typing import Optional, Type, Union, Tuple
from torch import nn as nn
from .grn import GlobalResponseNorm
from .helpers import to_2tuple
class Mlp(nn.Module):
"""... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
huggingface/pytorch-image-models | https://github.com/huggingface/pytorch-image-models/blob/31a85de79aad229c070c595c5ea0c43dfc95461e/timm/layers/diff_attention.py | timm/layers/diff_attention.py | """Differential Attention
Paper: 'Differential Transformer' - https://arxiv.org/abs/2410.05258
Reference impl: https://github.com/microsoft/unilm/tree/master/Diff-Transformer
Hacked together by / Copyright 2024, Ross Wightman
"""
import math
from typing import Optional, Type
import torch
import torch.nn as nn
impor... | python | Apache-2.0 | 31a85de79aad229c070c595c5ea0c43dfc95461e | 2026-01-04T14:41:55.902905Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.