mirror of
https://github.com/huggingface/pytorch-image-models.git
synced 2025-06-03 15:01:08 +08:00
Move opt_einsum import back out of class __init__
This commit is contained in:
parent
9ab5464e4d
commit
67ef6f0a92
@ -14,7 +14,15 @@ from typing import Any, Callable, Dict, Optional, Tuple, Union
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
|
||||
try:
|
||||
# NOTE opt_einsum needed to avoid blowing up memory with einsum ops
|
||||
import opt_einsum
|
||||
import torch.backends.opt_einsum
|
||||
torch.backends.opt_einsum.enabled = True
|
||||
torch.backends.opt_einsum.strategy = "auto-hq"
|
||||
has_opt_einsum = True
|
||||
except ImportError:
|
||||
has_opt_einsum = False
|
||||
|
||||
try:
|
||||
torch._dynamo.config.cache_size_limit = 1_000_000
|
||||
@ -92,14 +100,8 @@ class Kron(torch.optim.Optimizer):
|
||||
flatten_dim: bool = False,
|
||||
deterministic: bool = False,
|
||||
):
|
||||
try:
|
||||
# NOTE opt_einsum needed to avoid blowing up memory with einsum ops
|
||||
import opt_einsum
|
||||
opt_einsum.enabled = True
|
||||
opt_einsum.strategy = "auto-hq"
|
||||
import torch.backends.opt_einsum
|
||||
except ImportError:
|
||||
warnings.warn("It is highly recommended to have 'opt_einsum' installed for this optimizer." )
|
||||
if not has_opt_einsum:
|
||||
warnings.warn("It is highly recommended to have 'opt_einsum' installed for this optimizer.")
|
||||
|
||||
if not 0.0 <= lr:
|
||||
raise ValueError(f"Invalid learning rate: {lr}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user