warner-benjamin / fastxtend Goto Github PK
View Code? Open in Web Editor NEWTrain fastai models faster (and other useful tools)
Home Page: https://fastxtend.benjaminwarner.dev
License: MIT License
Train fastai models faster (and other useful tools)
Home Page: https://fastxtend.benjaminwarner.dev
License: MIT License
I'm following the examples for fine tuning with HF Transformers.
When executing the Learner, the following error is thrown:
learn.model.save_pretrained("pythia-70m-trained")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
[<ipython-input-11-d1c51ba9b240>](https://localhost:8080/#) in <cell line: 1>()
----> 1 learn.model.save_pretrained("pythia-70m-trained")
[/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py](https://localhost:8080/#) in __getattr__(self, name)
1693 if name in modules:
1694 return modules[name]
-> 1695 raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
1696
1697 def __setattr__(self, name: str, value: Union[Tensor, 'Module']) -> None:
AttributeError: 'HuggingFaceWrapper' object has no attribute 'save_pretrained'
From reading the source, it looks like the model is encapsulated, not inherited? Which would mean that the desired method is bound to self.model
?
Running the following script in Google Colab:
from fastai.text.all import *
from fastxtend.text.all import *
from datasets import load_dataset
from transformers import AutoModel, AutoTokenizer, DataCollatorWithPadding
dataset = load_dataset("TinyPixel/orca-mini", split='train').train_test_split(test_size=0.3)
model_name = "EleutherAI/pythia-70m"
model = AutoModel.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained('distilroberta-base')
batch_size = 5
data_collator=DataCollatorWithPadding(tokenizer)
train_dataloader = HuggingFaceLoader(
dataset['train'].with_format('torch'), batch_size=batch_size,
collate_fn=data_collator, shuffle=True,
drop_last=True, num_workers=num_cpus()
)
valid_dataloader = HuggingFaceLoader(
dataset['test'].with_format('torch'), batch_size=16,
collate_fn=DataCollatorWithPadding(tokenizer), shuffle=False,
drop_last=False, num_workers=num_cpus()
)
dls = DataLoaders(train_dataloader, valid_dataloader)
learn = Learner(
dls,
model,
loss_func=HuggingFaceLoss(),
cbs=HuggingFaceCallback()
).to_bf16()
learn.model.save_pretrained("pythia-70m-trained")
I'm running fastxtend version 0.0.18 and fastai version 2.7.11.
My dataloader init, model init and training code is a bit fragmented, but I'll try to piece it back together here for reproducibility.
It looks something like this:
db = DataBlock(
blocks=blocks,
getters=getters,
n_inp=1,
item_tfms=Resize(resize),
batch_tfms=[*aug_transforms(), Normalize.from_stats(*imagenet_stats)],
splitter=splitter,
)
dls = db.dataloaders(df, bs=bs)
cbs = [ProgressiveResize(), CutMixUpAugment()]
learn = vision_learner(dls, arch=resnet50, opt_func=opt_func, loss_func=loss_func, cbs=cbs, metrics=metrics)
learn._fine_tune(epochs=epochs, base_lr=base_lr)
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ <ipython-input-23-4a152cf4a778>:1 in <cell line: 1> │
│ <ipython-input-8-78506829a822>:20 in mlbl_fine_tune │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/callback/schedule.py:168 in │
│ fine_tune │
│ │
│ 165 │ self.fit_one_cycle(freeze_epochs, slice(base_lr), pct_start=0.99, **kwargs) │
│ 166 │ base_lr /= 2 │
│ 167 │ self.unfreeze() │
│ ❱ 168 │ self.fit_one_cycle(epochs, slice(base_lr/lr_mult, base_lr), pct_start=pct_start, div │
│ 169 │
│ 170 # %% ../../nbs/14_callback.schedule.ipynb 67 │
│ 171 @docs │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/callback/schedule.py:119 in │
│ fit_one_cycle │
│ │
│ 116 │ lr_max = np.array([h['lr'] for h in self.opt.hypers]) │
│ 117 │ scheds = {'lr': combined_cos(pct_start, lr_max/div, lr_max, lr_max/div_final), │
│ 118 │ │ │ 'mom': combined_cos(pct_start, *(self.moms if moms is None else moms))} │
│ ❱ 119 │ self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd, sta │
│ 120 │
│ 121 # %% ../../nbs/14_callback.schedule.ipynb 50 │
│ 122 @patch │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/learner.py:264 in fit │
│ │
│ 261 │ │ │ if wd is not None: self.opt.set_hypers(wd=wd) │
│ 262 │ │ │ self.opt.set_hypers(lr=self.lr if lr is None else lr) │
│ 263 │ │ │ self.n_epoch = n_epoch │
│ ❱ 264 │ │ │ self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup │
│ 265 │ │
│ 266 │ def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),( │
│ 267 │ def __enter__(self): self(_before_epoch); return self │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/learner.py:199 in _with_events │
│ │
│ 196 │ │ self.xb,self.yb = b[:i],b[i:] │
│ 197 │ │
│ 198 │ def _with_events(self, f, event_type, ex, final=noop): │
│ ❱ 199 │ │ try: self(f'before_{event_type}'); f() │
│ 200 │ │ except ex: self(f'after_cancel_{event_type}') │
│ 201 │ │ self(f'after_{event_type}'); final() │
│ 202 │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/learner.py:253 in _do_fit │
│ │
│ 250 │ def _do_fit(self): │
│ 251 │ │ for epoch in range(self.n_epoch): │
│ 252 │ │ │ self.epoch=epoch │
│ ❱ 253 │ │ │ self._with_events(self._do_epoch, 'epoch', CancelEpochException) │
│ 254 │ │
│ 255 │ def fit(self, n_epoch, lr=None, wd=None, cbs=None, reset_opt=False, start_epoch=0): │
│ 256 │ │ if start_epoch != 0: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/learner.py:199 in _with_events │
│ │
│ 196 │ │ self.xb,self.yb = b[:i],b[i:] │
│ 197 │ │
│ 198 │ def _with_events(self, f, event_type, ex, final=noop): │
│ ❱ 199 │ │ try: self(f'before_{event_type}'); f() │
│ 200 │ │ except ex: self(f'after_cancel_{event_type}') │
│ 201 │ │ self(f'after_{event_type}'); final() │
│ 202 │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/learner.py:247 in _do_epoch │
│ │
│ 244 │ │ with torch.no_grad(): self._with_events(self.all_batches, 'validate', CancelVali │
│ 245 │ │
│ 246 │ def _do_epoch(self): │
│ ❱ 247 │ │ self._do_epoch_train() │
│ 248 │ │ self._do_epoch_validate() │
│ 249 │ │
│ 250 │ def _do_fit(self): │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/learner.py:239 in _do_epoch_train │
│ │
│ 236 │ │
│ 237 │ def _do_epoch_train(self): │
│ 238 │ │ self.dl = self.dls.train │
│ ❱ 239 │ │ self._with_events(self.all_batches, 'train', CancelTrainException) │
│ 240 │ │
│ 241 │ def _do_epoch_validate(self, ds_idx=1, dl=None): │
│ 242 │ │ if dl is None: dl = self.dls[ds_idx] │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/learner.py:199 in _with_events │
│ │
│ 196 │ │ self.xb,self.yb = b[:i],b[i:] │
│ 197 │ │
│ 198 │ def _with_events(self, f, event_type, ex, final=noop): │
│ ❱ 199 │ │ try: self(f'before_{event_type}'); f() │
│ 200 │ │ except ex: self(f'after_cancel_{event_type}') │
│ 201 │ │ self(f'after_{event_type}'); final() │
│ 202 │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastxtend/callback/simpleprofiler.py:85 in │
│ all_batches │
│ │
│ 82 │ │ │ self.one_batch(i, next(self.it)) │
│ 83 │ │ del(self.it) │
│ 84 │ else: │
│ ❱ 85 │ │ for o in enumerate(self.dl): self.one_batch(*o) │
│ 86 │
│ 87 # %% ../../nbs/callback.simpleprofiler.ipynb 18 │
│ 88 _loop = ['Start Fit', 'before_fit', 'Start Epoch Loop', 'before_epoch', 'Start Train', ' │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/learner.py:235 in one_batch │
│ │
│ 232 │ │ self.iter = i │
│ 233 │ │ b = self._set_device(b) │
│ 234 │ │ self._split(b) │
│ ❱ 235 │ │ self._with_events(self._do_one_batch, 'batch', CancelBatchException) │
│ 236 │ │
│ 237 │ def _do_epoch_train(self): │
│ 238 │ │ self.dl = self.dls.train │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/learner.py:199 in _with_events │
│ │
│ 196 │ │ self.xb,self.yb = b[:i],b[i:] │
│ 197 │ │
│ 198 │ def _with_events(self, f, event_type, ex, final=noop): │
│ ❱ 199 │ │ try: self(f'before_{event_type}'); f() │
│ 200 │ │ except ex: self(f'after_cancel_{event_type}') │
│ 201 │ │ self(f'after_{event_type}'); final() │
│ 202 │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/learner.py:172 in __call__ │
│ │
│ 169 │ │ finally: self.add_cbs(cbs) │
│ 170 │ │
│ 171 │ def ordered_cbs(self, event): return [cb for cb in self.cbs.sorted('order') if hasat │
│ ❱ 172 │ def __call__(self, event_name): L(event_name).map(self._call_one) │
│ 173 │ │
│ 174 │ def _call_one(self, event_name): │
│ 175 │ │ if not hasattr(event, event_name): raise Exception(f'missing {event_name}') │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastcore/foundation.py:156 in map │
│ │
│ 153 │ @classmethod │
│ 154 │ def range(cls, a, b=None, step=None): return cls(range_of(a, b=b, step=step)) │
│ 155 │ │
│ ❱ 156 │ def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args │
│ 157 │ def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, ne │
│ 158 │ def argfirst(self, f, negate=False): return first(i for i,o in self.enumerate() if f │
│ 159 │ def filter(self, f=noop, negate=False, gen=False, **kwargs): │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastcore/basics.py:840 in map_ex │
│ │
│ 837 │ │ else f.__getitem__) │
│ 838 │ res = map(g, iterable) │
│ 839 │ if gen: return res │
│ ❱ 840 │ return list(res) │
│ 841 │
│ 842 # %% ../nbs/01_basics.ipynb 336 │
│ 843 def compose(*funcs, order=None): │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastcore/basics.py:825 in __call__ │
│ │
│ 822 │ │ for k,v in kwargs.items(): │
│ 823 │ │ │ if isinstance(v,_Arg): kwargs[k] = args.pop(v.i) │
│ 824 │ │ fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[sel │
│ ❱ 825 │ │ return self.func(*fargs, **kwargs) │
│ 826 │
│ 827 # %% ../nbs/01_basics.ipynb 326 │
│ 828 def mapt(func, *iterables): │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastxtend/callback/simpleprofiler.py:72 in │
│ _call_one │
│ │
│ 69 @patch │
│ 70 def _call_one(self:Learner, event_name): │
│ 71 │ if not hasattr(event, event_name): raise Exception(f'missing {event_name}') │
│ ❱ 72 │ for cb in self.cbs.sorted('order'): cb(event_name) │
│ 73 │
│ 74 # %% ../../nbs/callback.simpleprofiler.ipynb 16 │
│ 75 @patch │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastxtend/callback/simpleprofiler.py:60 in │
│ __call__ │
│ │
│ 57 │ │ │ (self.run_valid and not getattr(self, 'training', False))) │
│ 58 │ res = None │
│ 59 │ if self.run and _run: │
│ ❱ 60 │ │ try: res = getattr(self, event_name, noop)() │
│ 61 │ │ except (CancelBatchException, CancelEpochException, CancelFitException, CancelSt │
│ 62 │ │ except Exception as e: │
│ 63 │ │ │ e.args = [f'Exception occured in `{self.__class__.__name__}` when calling ev │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastxtend/callback/cutmixup.py:292 in │
│ before_batch │
│ │
│ 289 │ │ │ # Apply MixUp/CutMix Augmentations to MixUp and CutMix samples │
│ 290 │ │ │ if do_mix or do_cut: │
│ 291 │ │ │ │ if self._docutmixaug: │
│ ❱ 292 │ │ │ │ │ xb2[aug_type<2] = self._cutmixaugs_pipe(xb[aug_type<2]) │
│ 293 │ │ │ │ else: │
│ 294 │ │ │ │ │ xb2[aug_type<2] = xb[aug_type<2] │
│ 295 │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/torch_core.py:372 in │
│ __torch_function__ │
│ │
│ 369 │ def __torch_function__(cls, func, types, args=(), kwargs=None): │
│ 370 │ │ if cls.debug and func.__name__ not in ('__str__','__repr__'): print(func, types, │
│ 371 │ │ if _torch_handled(args, cls._opt, func): types = (torch.Tensor,) │
│ ❱ 372 │ │ res = super().__torch_function__(func, types, args, ifnone(kwargs, {})) │
│ 373 │ │ dict_objs = _find_args(args) if args else _find_args(list(kwargs.values())) │
│ 374 │ │ if issubclass(type(res),TensorBase) and dict_objs: res.set_meta(dict_objs[0],as_ │
│ 375 │ │ elif dict_objs and is_listy(res): [r.set_meta(dict_objs[0],as_copy=True) for r i │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/torch/_tensor.py:1279 in │
│ __torch_function__ │
│ │
│ 1276 │ │ │ return NotImplemented │
│ 1277 │ │ │
│ 1278 │ │ with _C.DisableTorchFunction(): │
│ ❱ 1279 │ │ │ ret = func(*args, **kwargs) │
│ 1280 │ │ │ if func in get_default_nowrap_functions(): │
│ 1281 │ │ │ │ return ret │
│ 1282 │ │ │ else: │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
RuntimeError: Exception occured in `CutMixUpAugment` when calling event `before_batch`:
shape mismatch: value tensor of shape [21, 3, 224, 224] cannot be broadcast to indexing result of shape
[21, 3, 80, 80]
Removing aug_transforms from batch_tfms in the DataBlock init fixed it for me.
Specifying ProgressiveResize()
in the callbacks list and calling learn.fine_tune
leads to ProgressiveResize being run for two separate training runs.
If I manually call all of the fine_tune steps, I can add the callback to only the unfrozen epochs, but fine_tune will run at the Resize
size rather than the initial size.
My hypothesis is that we would see better training performance if the frozen epochs were run at the initial size. What's the simplest way to accomplish this with the callback?
I'm encountering the following when trying to import fastextend: AttributeError: 'function' object has no attribute '__base__'
Steps to reproduce: Installed fastai, ran pip install fastxtend[vision]
, then tried to import in my jupyter notebook.
Traceback:
from fastxtend.vision.all import *
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[17], line 1
----> 1 from fastxtend.vision.all import *
File /usr/local/lib/python3.8/dist-packages/fastxtend/vision/all.py:2
1 from ..basics import *
----> 2 from ..callback.all import *
3 from .data import *
4 from ..data.all import *
File /usr/local/lib/python3.8/dist-packages/fastxtend/callback/all.py:9
6 from .channelslast import *
8 from .cutmixup import *
----> 9 from .ema import *
10 from .lr_finder import *
11 from .progresize import *
File /usr/local/lib/python3.8/dist-packages/fastxtend/callback/ema.py:18
15 from fastai.callback.fp16 import MixedPrecision
16 from fastai.callback.schedule import SchedCos, _Annealer
---> 18 from .utils import *
19 from ..imports import *
21 # %% auto 0
File /usr/local/lib/python3.8/dist-packages/fastxtend/callback/utils.py:38
32 available_loggers = {
33 'wandb': WANDB,
34 'tensorboard': TENSORBOARD
35 }
37 # %% ../../nbs/callback.utils.ipynb 7
---> 38 class LogDispatch(Callback):
39 "A default callback for dispatching additional values to loggers"
40 run_valid, order = False, Recorder.order+2
File /usr/local/lib/python3.8/dist-packages/fastxtend/callback/utils.py:66, in LogDispatch()
62 for log in self.loggers:
63 log(self.valid_values)
65 @delegates(wandb.Table if WANDB else None)
---> 66 def log_wandb_table(self, name:str, **kwargs):
67 "Log `wandb.Table` to Weights and Biases. See `wandb.Table` for details"
68 if WANDB:
File /usr/local/lib/python3.8/dist-packages/fastcore/meta.py:115, in delegates.<locals>._f(f)
114 def _f(f):
--> 115 if to is None: to_f,from_f = f.__base__.__init__,f.__init__
116 else: to_f,from_f = to.__init__ if isinstance(to,type) else to,f
117 from_f = getattr(from_f,'__func__',from_f)
AttributeError: 'function' object has no attribute '__base__'
Just tried out the fastxtend BCEWithLogitsLoss function and I'm hitting the following error:
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /tmp/ipykernel_240/2586047162.py:29 in <module> │
│ │
│ [Errno 2] No such file or directory: '/tmp/ipykernel_240/2586047162.py' │
│ │
│ /tmp/ipykernel_240/2481592728.py:38 in mlbl_fine_tune │
│ │
│ [Errno 2] No such file or directory: '/tmp/ipykernel_240/2481592728.py' │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastai/callback/schedule.py:119 in fit_one_cycle │
│ │
│ 116 │ lr_max = np.array([h['lr'] for h in self.opt.hypers]) │
│ 117 │ scheds = {'lr': combined_cos(pct_start, lr_max/div, lr_max, lr_max/div_final), │
│ 118 │ │ │ 'mom': combined_cos(pct_start, *(self.moms if moms is None else moms))} │
│ ❱ 119 │ self.fit(n_epoch, cbs=ParamScheduler(scheds)+L(cbs), reset_opt=reset_opt, wd=wd, sta │
│ 120 │
│ 121 # %% ../nbs/14_callback.schedule.ipynb 51 │
│ 122 @patch │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastai/learner.py:256 in fit │
│ │
│ 253 │ │ │ if wd is not None: self.opt.set_hypers(wd=wd) │
│ 254 │ │ │ self.opt.set_hypers(lr=self.lr if lr is None else lr) │
│ 255 │ │ │ self.n_epoch = n_epoch │
│ ❱ 256 │ │ │ self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup │
│ 257 │ │
│ 258 │ def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),( │
│ 259 │ def __enter__(self): self(_before_epoch); return self │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastai/learner.py:193 in _with_events │
│ │
│ 190 │ │ self.xb,self.yb = b[:i],b[i:] │
│ 191 │ │
│ 192 │ def _with_events(self, f, event_type, ex, final=noop): │
│ ❱ 193 │ │ try: self(f'before_{event_type}'); f() │
│ 194 │ │ except ex: self(f'after_cancel_{event_type}') │
│ 195 │ │ self(f'after_{event_type}'); final() │
│ 196 │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastai/learner.py:245 in _do_fit │
│ │
│ 242 │ def _do_fit(self): │
│ 243 │ │ for epoch in range(self.n_epoch): │
│ 244 │ │ │ self.epoch=epoch │
│ ❱ 245 │ │ │ self._with_events(self._do_epoch, 'epoch', CancelEpochException) │
│ 246 │ │
│ 247 │ def fit(self, n_epoch, lr=None, wd=None, cbs=None, reset_opt=False, start_epoch=0): │
│ 248 │ │ if start_epoch != 0: │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastai/learner.py:193 in _with_events │
│ │
│ 190 │ │ self.xb,self.yb = b[:i],b[i:] │
│ 191 │ │
│ 192 │ def _with_events(self, f, event_type, ex, final=noop): │
│ ❱ 193 │ │ try: self(f'before_{event_type}'); f() │
│ 194 │ │ except ex: self(f'after_cancel_{event_type}') │
│ 195 │ │ self(f'after_{event_type}'); final() │
│ 196 │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastai/learner.py:240 in _do_epoch │
│ │
│ 237 │ │
│ 238 │ def _do_epoch(self): │
│ 239 │ │ self._do_epoch_train() │
│ ❱ 240 │ │ self._do_epoch_validate() │
│ 241 │ │
│ 242 │ def _do_fit(self): │
│ 243 │ │ for epoch in range(self.n_epoch): │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastai/learner.py:236 in _do_epoch_validate │
│ │
│ 233 │ def _do_epoch_validate(self, ds_idx=1, dl=None): │
│ 234 │ │ if dl is None: dl = self.dls[ds_idx] │
│ 235 │ │ self.dl = dl │
│ ❱ 236 │ │ with torch.no_grad(): self._with_events(self.all_batches, 'validate', CancelVali │
│ 237 │ │
│ 238 │ def _do_epoch(self): │
│ 239 │ │ self._do_epoch_train() │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastai/learner.py:195 in _with_events │
│ │
│ 192 │ def _with_events(self, f, event_type, ex, final=noop): │
│ 193 │ │ try: self(f'before_{event_type}'); f() │
│ 194 │ │ except ex: self(f'after_cancel_{event_type}') │
│ ❱ 195 │ │ self(f'after_{event_type}'); final() │
│ 196 │ │
│ 197 │ def all_batches(self): │
│ 198 │ │ self.n_iter = len(self.dl) │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastai/learner.py:171 in __call__ │
│ │
│ 168 │ │ finally: self.add_cbs(cbs) │
│ 169 │ │
│ 170 │ def ordered_cbs(self, event): return [cb for cb in self.cbs.sorted('order') if hasat │
│ ❱ 171 │ def __call__(self, event_name): L(event_name).map(self._call_one) │
│ 172 │ │
│ 173 │ def _call_one(self, event_name): │
│ 174 │ │ if not hasattr(event, event_name): raise Exception(f'missing {event_name}') │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastcore/foundation.py:156 in map │
│ │
│ 153 │ @classmethod │
│ 154 │ def range(cls, a, b=None, step=None): return cls(range_of(a, b=b, step=step)) │
│ 155 │ │
│ ❱ 156 │ def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args │
│ 157 │ def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, ne │
│ 158 │ def argfirst(self, f, negate=False): return first(i for i,o in self.enumerate() if f │
│ 159 │ def filter(self, f=noop, negate=False, gen=False, **kwargs): │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastcore/basics.py:840 in map_ex │
│ │
│ 837 │ │ else f.__getitem__) │
│ 838 │ res = map(g, iterable) │
│ 839 │ if gen: return res │
│ ❱ 840 │ return list(res) │
│ 841 │
│ 842 # %% ../nbs/01_basics.ipynb 336 │
│ 843 def compose(*funcs, order=None): │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastcore/basics.py:825 in __call__ │
│ │
│ 822 │ │ for k,v in kwargs.items(): │
│ 823 │ │ │ if isinstance(v,_Arg): kwargs[k] = args.pop(v.i) │
│ 824 │ │ fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[sel │
│ ❱ 825 │ │ return self.func(*fargs, **kwargs) │
│ 826 │
│ 827 # %% ../nbs/01_basics.ipynb 326 │
│ 828 def mapt(func, *iterables): │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastai/learner.py:175 in _call_one │
│ │
│ 172 │ │
│ 173 │ def _call_one(self, event_name): │
│ 174 │ │ if not hasattr(event, event_name): raise Exception(f'missing {event_name}') │
│ ❱ 175 │ │ for cb in self.cbs.sorted('order'): cb(event_name) │
│ 176 │ │
│ 177 │ def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias). │
│ 178 │ def create_opt(self): │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastai/callback/core.py:62 in __call__ │
│ │
│ 59 │ │ if self.run and _run: │
│ 60 │ │ │ try: res = getcallable(self, event_name)() │
│ 61 │ │ │ except (CancelBatchException, CancelBackwardException, CancelEpochException, │
│ ❱ 62 │ │ │ except Exception as e: raise modify_exception(e, f'Exception occured in `{se │
│ 63 │ │ if event_name=='after_fit': self.run=True #Reset self.run to True at each end of │
│ 64 │ │ return res │
│ 65 │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastai/callback/core.py:60 in __call__ │
│ │
│ 57 │ │ │ (self.run_valid and not getattr(self, 'training', False))) │
│ 58 │ │ res = None │
│ 59 │ │ if self.run and _run: │
│ ❱ 60 │ │ │ try: res = getcallable(self, event_name)() │
│ 61 │ │ │ except (CancelBatchException, CancelBackwardException, CancelEpochException, │
│ 62 │ │ │ except Exception as e: raise modify_exception(e, f'Exception occured in `{se │
│ 63 │ │ if event_name=='after_fit': self.run=True #Reset self.run to True at each end of │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastai/callback/core.py:186 in after_validate │
│ │
│ 183 │ │ "Fetch predictions from `Learner` without `self.cbs` and `remove_on_fetch` callb │
│ 184 │ │ to_rm = L(cb for cb in self.learn.cbs if getattr(cb, 'remove_on_fetch', False)) │
│ 185 │ │ with self.learn.removed_cbs(to_rm + self.cbs) as learn: │
│ ❱ 186 │ │ │ self.preds = learn.get_preds(ds_idx=self.ds_idx, dl=self.dl, │
│ 187 │ │ │ │ with_input=self.with_input, with_decoded=self.with_decoded, inner=True, │
│ 188 │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastai/learner.py:296 in get_preds │
│ │
│ 293 │ │ │ pred_i = 1 if with_input else 0 │
│ 294 │ │ │ if res[pred_i] is not None: │
│ 295 │ │ │ │ res[pred_i] = act(res[pred_i]) │
│ ❱ 296 │ │ │ │ if with_decoded: res.insert(pred_i+2, getcallable(self.loss_func, 'decod │
│ 297 │ │ │ if reorder and hasattr(dl, 'get_idxs'): res = nested_reorder(res, tensor(idx │
│ 298 │ │ │ return tuple(res) │
│ 299 │ │ self._end_cleanup() │
│ │
│ /opt/conda/lib/python3.10/site-packages/fastxtend/losses.py:45 in decodes │
│ │
│ 42 │ │
│ 43 │ def decodes(self, x:Tensor) -> Tensor: │
│ 44 │ │ "Converts model output to target format" │
│ ❱ 45 │ │ return x>self.thresh │
│ 46 │ │
│ 47 │ def activation(self, x:Tensor) -> Tensor: │
│ 48 │ │ "`nn.BCEWithLogitsLoss`'s fused activation function applied to model output" │
│ │
│ /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1207 in __getattr__ │
│ │
│ 1204 │ │ │ modules = self.__dict__['_modules'] │
│ 1205 │ │ │ if name in modules: │
│ 1206 │ │ │ │ return modules[name] │
│ ❱ 1207 │ │ raise AttributeError("'{}' object has no attribute '{}'".format( │
│ 1208 │ │ │ type(self).__name__, name)) │
│ 1209 │ │
│ 1210 │ def __setattr__(self, name: str, value: Union[Tensor, 'Module']) -> None: │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: Exception occured in `FetchPredsCallback` when calling event `after_validate`:
'BCEWithLogitsLoss' object has no attribute 'thresh'
Hi Benjamin,
I am trying to train a classifier with the melspectogram using the audio module.
Here is datablock instantiation:
dbl = DataBlock(blocks=(MelSpecBlock(TensorAudio), CategoryBlock),
get_x = ColReader("filename", pref=data_path/"sollicited"),
splitter = CrossValidationSplitter(col='kfold', fold=0),
get_y = ColReader("tb_status")
)
dls = dbl.dataloaders(train_df, bs=5)
then executing the code dls.show_batch(max_n=1)
produce this error:
...
--> 697 res = L(b).map(partial(batch_to_samples,max_n=max_n))
698 return retain_types(res.zip(), [b])
699
RecursionError: maximum recursion depth exceeded while calling a Python object
More importantly, I have applied the one_batch()
method, but the input was still the
filename not a TensorAudio
or MelSpectrogram
object !
I think that is the problem.
The documentation for CutMixUpAugment says "Use augment_finetune
to only apply dataloader augmentations at the end of training."
Reviewing the code however, it appears that augment_finetune
applies the augmentations at the beginning of training only.
if self.element and self.augment_finetune >= self.learn.pct_train:
Let's assume I want to only apply augmentations for the last 20% of training. self.augment_finetune=0.2
.
During the first epoch, the check would be
if True and 0.2 >= 0.0:
Meaning that the augmentations would be applied on the first epoch(and the first 20% of training.
I might be missing something, but I think the check should be:
if self.element and self.augment_finetune >= 1 - self.learn.pct_train:
Great library! I had actually independently implemented some of the loss utilities that you wrote. Glad to see them in a public repo with better names.
Unfortunately, when I try to load the packages with from fastxtend.vision.all import *
, running learn.lr_find
fails because it attempts to deepcopy learn.dls
.
Here's the headline of the stacktrace:
RuntimeError: Exception occured in `LRFinder` when calling event `before_fit`:
The default implementation of __deepcopy__() for non-wrapper subclasses only works for subclass types that
implement new_empty() and for which that function returns another instance of the same subclass. You should either
properly implement new_empty() for your subclass or override __deepcopy__() if it is intended behavior for
new_empty() to return an instance of a different type.
> /home/csaroff/.miniconda3/lib/python3.9/site-packages/torch/_tensor.py(185)__deepcopy__()
183 new_tensor = self.new_empty([])
184 if type(new_tensor) is not type(self):
--> 185 raise RuntimeError(
186 "The default implementation of __deepcopy__() for non-wrapper subclasses "
187 "only works for subclass types that implement new_empty() and for which "
I tried opening the debugger and it seems like targ_pts
is unable to be deepcopied.
I wasn't sure if you've run into this before and might have some insight. In case it's helpful, I'm running fastai version 2.7.11
and fastxtend version 0.0.18
.
>>> fastai.__version__
'2.7.11'
tor>>> torch.__version__
'1.13.1+cu116'
>>> fastxtend.__version__
'0.0.18'
I also tried downgrading to 2.7.10
, but had the same issue.
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ <ipython-input-19-c2db1576f5af>:14 in <cell line: 14> │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastxtend/callback/lr_finder.py:81 in │
│ lr_find │
│ │
│ 78 │ """ │
│ 79 │ n_epoch = num_it//len(self.dls.train) + 1 │
│ 80 │ cb=LRFinder(start_lr=start_lr, end_lr=end_lr, num_it=num_it, stop_div=stop_div,resto │
│ ❱ 81 │ with self.no_logging(): self.fit(n_epoch, cbs=cb) │
│ 82 │ if suggest_funcs is not None: │
│ 83 │ │ lrs, losses = tensor(self.recorder.lrs[num_it//10:-5]), tensor(self.recorder.los │
│ 84 │ │ nan_idxs = torch.nonzero(torch.isnan(losses.view(-1))) │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/learner.py:264 in fit │
│ │
│ 261 │ │ │ if wd is not None: self.opt.set_hypers(wd=wd) │
│ 262 │ │ │ self.opt.set_hypers(lr=self.lr if lr is None else lr) │
│ 263 │ │ │ self.n_epoch = n_epoch │
│ ❱ 264 │ │ │ self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup │
│ 265 │ │
│ 266 │ def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),( │
│ 267 │ def __enter__(self): self(_before_epoch); return self │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/learner.py:199 in _with_events │
│ │
│ 196 │ │ self.xb,self.yb = b[:i],b[i:] │
│ 197 │ │
│ 198 │ def _with_events(self, f, event_type, ex, final=noop): │
│ ❱ 199 │ │ try: self(f'before_{event_type}'); f() │
│ 200 │ │ except ex: self(f'after_cancel_{event_type}') │
│ 201 │ │ self(f'after_{event_type}'); final() │
│ 202 │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/learner.py:172 in __call__ │
│ │
│ 169 │ │ finally: self.add_cbs(cbs) │
│ 170 │ │
│ 171 │ def ordered_cbs(self, event): return [cb for cb in self.cbs.sorted('order') if hasat │
│ ❱ 172 │ def __call__(self, event_name): L(event_name).map(self._call_one) │
│ 173 │ │
│ 174 │ def _call_one(self, event_name): │
│ 175 │ │ if not hasattr(event, event_name): raise Exception(f'missing {event_name}') │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastcore/foundation.py:156 in map │
│ │
│ 153 │ @classmethod │
│ 154 │ def range(cls, a, b=None, step=None): return cls(range_of(a, b=b, step=step)) │
│ 155 │ │
│ ❱ 156 │ def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args │
│ 157 │ def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, ne │
│ 158 │ def argfirst(self, f, negate=False): return first(i for i,o in self.enumerate() if f │
│ 159 │ def filter(self, f=noop, negate=False, gen=False, **kwargs): │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastcore/basics.py:840 in map_ex │
│ │
│ 837 │ │ else f.__getitem__) │
│ 838 │ res = map(g, iterable) │
│ 839 │ if gen: return res │
│ ❱ 840 │ return list(res) │
│ 841 │
│ 842 # %% ../nbs/01_basics.ipynb 336 │
│ 843 def compose(*funcs, order=None): │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastcore/basics.py:825 in __call__ │
│ │
│ 822 │ │ for k,v in kwargs.items(): │
│ 823 │ │ │ if isinstance(v,_Arg): kwargs[k] = args.pop(v.i) │
│ 824 │ │ fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[sel │
│ ❱ 825 │ │ return self.func(*fargs, **kwargs) │
│ 826 │
│ 827 # %% ../nbs/01_basics.ipynb 326 │
│ 828 def mapt(func, *iterables): │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/learner.py:176 in _call_one │
│ │
│ 173 │ │
│ 174 │ def _call_one(self, event_name): │
│ 175 │ │ if not hasattr(event, event_name): raise Exception(f'missing {event_name}') │
│ ❱ 176 │ │ for cb in self.cbs.sorted('order'): cb(event_name) │
│ 177 │ │
│ 178 │ def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias). │
│ 179 │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/callback/core.py:62 in __call__ │
│ │
│ 59 │ │ if self.run and _run: │
│ 60 │ │ │ try: res = getcallable(self, event_name)() │
│ 61 │ │ │ except (CancelBatchException, CancelBackwardException, CancelEpochException, │
│ ❱ 62 │ │ │ except Exception as e: raise modify_exception(e, f'Exception occured in `{se │
│ 63 │ │ if event_name=='after_fit': self.run=True #Reset self.run to True at each end of │
│ 64 │ │ return res │
│ 65 │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/callback/core.py:60 in __call__ │
│ │
│ 57 │ │ │ (self.run_valid and not getattr(self, 'training', False))) │
│ 58 │ │ res = None │
│ 59 │ │ if self.run and _run: │
│ ❱ 60 │ │ │ try: res = getcallable(self, event_name)() │
│ 61 │ │ │ except (CancelBatchException, CancelBackwardException, CancelEpochException, │
│ 62 │ │ │ except Exception as e: raise modify_exception(e, f'Exception occured in `{se │
│ 63 │ │ if event_name=='after_fit': self.run=True #Reset self.run to True at each end of │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastxtend/callback/lr_finder.py:36 in │
│ before_fit │
│ │
│ 33 │ │ "Initialize container for hyper-parameters and save the model & optimizer, optio │
│ 34 │ │ super().before_fit() │
│ 35 │ │ if self.restore_state: │
│ ❱ 36 │ │ │ self.old_dls = deepcopy(self.learn.dls) │
│ 37 │ │ │ self.states = get_random_states() │
│ 38 │ │ path = self.path/self.model_dir │
│ 39 │ │ path.mkdir(parents=True, exist_ok=True) │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:172 in deepcopy │
│ │
│ 169 │ │ │ │ if isinstance(rv, str): │
│ 170 │ │ │ │ │ y = x │
│ 171 │ │ │ │ else: │
│ ❱ 172 │ │ │ │ │ y = _reconstruct(x, memo, *rv) │
│ 173 │ │
│ 174 │ # If is its own copy, don't memoize. │
│ 175 │ if y is not x: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:270 in _reconstruct │
│ │
│ 267 │ │
│ 268 │ if state is not None: │
│ 269 │ │ if deep: │
│ ❱ 270 │ │ │ state = deepcopy(state, memo) │
│ 271 │ │ if hasattr(y, '__setstate__'): │
│ 272 │ │ │ y.__setstate__(state) │
│ 273 │ │ else: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:146 in deepcopy │
│ │
│ 143 │ │
│ 144 │ copier = _deepcopy_dispatch.get(cls) │
│ 145 │ if copier is not None: │
│ ❱ 146 │ │ y = copier(x, memo) │
│ 147 │ else: │
│ 148 │ │ if issubclass(cls, type): │
│ 149 │ │ │ y = _deepcopy_atomic(x, memo) │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:230 in _deepcopy_dict │
│ │
│ 227 │ y = {} │
│ 228 │ memo[id(x)] = y │
│ 229 │ for key, value in x.items(): │
│ ❱ 230 │ │ y[deepcopy(key, memo)] = deepcopy(value, memo) │
│ 231 │ return y │
│ 232 d[dict] = _deepcopy_dict │
│ 233 if PyStringMap is not None: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:146 in deepcopy │
│ │
│ 143 │ │
│ 144 │ copier = _deepcopy_dispatch.get(cls) │
│ 145 │ if copier is not None: │
│ ❱ 146 │ │ y = copier(x, memo) │
│ 147 │ else: │
│ 148 │ │ if issubclass(cls, type): │
│ 149 │ │ │ y = _deepcopy_atomic(x, memo) │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:205 in _deepcopy_list │
│ │
│ 202 │ memo[id(x)] = y │
│ 203 │ append = y.append │
│ 204 │ for a in x: │
│ ❱ 205 │ │ append(deepcopy(a, memo)) │
│ 206 │ return y │
│ 207 d[list] = _deepcopy_list │
│ 208 │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:172 in deepcopy │
│ │
│ 169 │ │ │ │ if isinstance(rv, str): │
│ 170 │ │ │ │ │ y = x │
│ 171 │ │ │ │ else: │
│ ❱ 172 │ │ │ │ │ y = _reconstruct(x, memo, *rv) │
│ 173 │ │
│ 174 │ # If is its own copy, don't memoize. │
│ 175 │ if y is not x: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:270 in _reconstruct │
│ │
│ 267 │ │
│ 268 │ if state is not None: │
│ 269 │ │ if deep: │
│ ❱ 270 │ │ │ state = deepcopy(state, memo) │
│ 271 │ │ if hasattr(y, '__setstate__'): │
│ 272 │ │ │ y.__setstate__(state) │
│ 273 │ │ else: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:146 in deepcopy │
│ │
│ 143 │ │
│ 144 │ copier = _deepcopy_dispatch.get(cls) │
│ 145 │ if copier is not None: │
│ ❱ 146 │ │ y = copier(x, memo) │
│ 147 │ else: │
│ 148 │ │ if issubclass(cls, type): │
│ 149 │ │ │ y = _deepcopy_atomic(x, memo) │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:230 in _deepcopy_dict │
│ │
│ 227 │ y = {} │
│ 228 │ memo[id(x)] = y │
│ 229 │ for key, value in x.items(): │
│ ❱ 230 │ │ y[deepcopy(key, memo)] = deepcopy(value, memo) │
│ 231 │ return y │
│ 232 d[dict] = _deepcopy_dict │
│ 233 if PyStringMap is not None: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:172 in deepcopy │
│ │
│ 169 │ │ │ │ if isinstance(rv, str): │
│ 170 │ │ │ │ │ y = x │
│ 171 │ │ │ │ else: │
│ ❱ 172 │ │ │ │ │ y = _reconstruct(x, memo, *rv) │
│ 173 │ │
│ 174 │ # If is its own copy, don't memoize. │
│ 175 │ if y is not x: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:270 in _reconstruct │
│ │
│ 267 │ │
│ 268 │ if state is not None: │
│ 269 │ │ if deep: │
│ ❱ 270 │ │ │ state = deepcopy(state, memo) │
│ 271 │ │ if hasattr(y, '__setstate__'): │
│ 272 │ │ │ y.__setstate__(state) │
│ 273 │ │ else: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:146 in deepcopy │
│ │
│ 143 │ │
│ 144 │ copier = _deepcopy_dispatch.get(cls) │
│ 145 │ if copier is not None: │
│ ❱ 146 │ │ y = copier(x, memo) │
│ 147 │ else: │
│ 148 │ │ if issubclass(cls, type): │
│ 149 │ │ │ y = _deepcopy_atomic(x, memo) │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:230 in _deepcopy_dict │
│ │
│ 227 │ y = {} │
│ 228 │ memo[id(x)] = y │
│ 229 │ for key, value in x.items(): │
│ ❱ 230 │ │ y[deepcopy(key, memo)] = deepcopy(value, memo) │
│ 231 │ return y │
│ 232 d[dict] = _deepcopy_dict │
│ 233 if PyStringMap is not None: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:172 in deepcopy │
│ │
│ 169 │ │ │ │ if isinstance(rv, str): │
│ 170 │ │ │ │ │ y = x │
│ 171 │ │ │ │ else: │
│ ❱ 172 │ │ │ │ │ y = _reconstruct(x, memo, *rv) │
│ 173 │ │
│ 174 │ # If is its own copy, don't memoize. │
│ 175 │ if y is not x: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:270 in _reconstruct │
│ │
│ 267 │ │
│ 268 │ if state is not None: │
│ 269 │ │ if deep: │
│ ❱ 270 │ │ │ state = deepcopy(state, memo) │
│ 271 │ │ if hasattr(y, '__setstate__'): │
│ 272 │ │ │ y.__setstate__(state) │
│ 273 │ │ else: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:146 in deepcopy │
│ │
│ 143 │ │
│ 144 │ copier = _deepcopy_dispatch.get(cls) │
│ 145 │ if copier is not None: │
│ ❱ 146 │ │ y = copier(x, memo) │
│ 147 │ else: │
│ 148 │ │ if issubclass(cls, type): │
│ 149 │ │ │ y = _deepcopy_atomic(x, memo) │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:230 in _deepcopy_dict │
│ │
│ 227 │ y = {} │
│ 228 │ memo[id(x)] = y │
│ 229 │ for key, value in x.items(): │
│ ❱ 230 │ │ y[deepcopy(key, memo)] = deepcopy(value, memo) │
│ 231 │ return y │
│ 232 d[dict] = _deepcopy_dict │
│ 233 if PyStringMap is not None: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:146 in deepcopy │
│ │
│ 143 │ │
│ 144 │ copier = _deepcopy_dispatch.get(cls) │
│ 145 │ if copier is not None: │
│ ❱ 146 │ │ y = copier(x, memo) │
│ 147 │ else: │
│ 148 │ │ if issubclass(cls, type): │
│ 149 │ │ │ y = _deepcopy_atomic(x, memo) │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:205 in _deepcopy_list │
│ │
│ 202 │ memo[id(x)] = y │
│ 203 │ append = y.append │
│ 204 │ for a in x: │
│ ❱ 205 │ │ append(deepcopy(a, memo)) │
│ 206 │ return y │
│ 207 d[list] = _deepcopy_list │
│ 208 │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:172 in deepcopy │
│ │
│ 169 │ │ │ │ if isinstance(rv, str): │
│ 170 │ │ │ │ │ y = x │
│ 171 │ │ │ │ else: │
│ ❱ 172 │ │ │ │ │ y = _reconstruct(x, memo, *rv) │
│ 173 │ │
│ 174 │ # If is its own copy, don't memoize. │
│ 175 │ if y is not x: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:270 in _reconstruct │
│ │
│ 267 │ │
│ 268 │ if state is not None: │
│ 269 │ │ if deep: │
│ ❱ 270 │ │ │ state = deepcopy(state, memo) │
│ 271 │ │ if hasattr(y, '__setstate__'): │
│ 272 │ │ │ y.__setstate__(state) │
│ 273 │ │ else: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:146 in deepcopy │
│ │
│ 143 │ │
│ 144 │ copier = _deepcopy_dispatch.get(cls) │
│ 145 │ if copier is not None: │
│ ❱ 146 │ │ y = copier(x, memo) │
│ 147 │ else: │
│ 148 │ │ if issubclass(cls, type): │
│ 149 │ │ │ y = _deepcopy_atomic(x, memo) │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:230 in _deepcopy_dict │
│ │
│ 227 │ y = {} │
│ 228 │ memo[id(x)] = y │
│ 229 │ for key, value in x.items(): │
│ ❱ 230 │ │ y[deepcopy(key, memo)] = deepcopy(value, memo) │
│ 231 │ return y │
│ 232 d[dict] = _deepcopy_dict │
│ 233 if PyStringMap is not None: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:172 in deepcopy │
│ │
│ 169 │ │ │ │ if isinstance(rv, str): │
│ 170 │ │ │ │ │ y = x │
│ 171 │ │ │ │ else: │
│ ❱ 172 │ │ │ │ │ y = _reconstruct(x, memo, *rv) │
│ 173 │ │
│ 174 │ # If is its own copy, don't memoize. │
│ 175 │ if y is not x: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:270 in _reconstruct │
│ │
│ 267 │ │
│ 268 │ if state is not None: │
│ 269 │ │ if deep: │
│ ❱ 270 │ │ │ state = deepcopy(state, memo) │
│ 271 │ │ if hasattr(y, '__setstate__'): │
│ 272 │ │ │ y.__setstate__(state) │
│ 273 │ │ else: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:146 in deepcopy │
│ │
│ 143 │ │
│ 144 │ copier = _deepcopy_dispatch.get(cls) │
│ 145 │ if copier is not None: │
│ ❱ 146 │ │ y = copier(x, memo) │
│ 147 │ else: │
│ 148 │ │ if issubclass(cls, type): │
│ 149 │ │ │ y = _deepcopy_atomic(x, memo) │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:230 in _deepcopy_dict │
│ │
│ 227 │ y = {} │
│ 228 │ memo[id(x)] = y │
│ 229 │ for key, value in x.items(): │
│ ❱ 230 │ │ y[deepcopy(key, memo)] = deepcopy(value, memo) │
│ 231 │ return y │
│ 232 d[dict] = _deepcopy_dict │
│ 233 if PyStringMap is not None: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:146 in deepcopy │
│ │
│ 143 │ │
│ 144 │ copier = _deepcopy_dispatch.get(cls) │
│ 145 │ if copier is not None: │
│ ❱ 146 │ │ y = copier(x, memo) │
│ 147 │ else: │
│ 148 │ │ if issubclass(cls, type): │
│ 149 │ │ │ y = _deepcopy_atomic(x, memo) │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:205 in _deepcopy_list │
│ │
│ 202 │ memo[id(x)] = y │
│ 203 │ append = y.append │
│ 204 │ for a in x: │
│ ❱ 205 │ │ append(deepcopy(a, memo)) │
│ 206 │ return y │
│ 207 d[list] = _deepcopy_list │
│ 208 │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:172 in deepcopy │
│ │
│ 169 │ │ │ │ if isinstance(rv, str): │
│ 170 │ │ │ │ │ y = x │
│ 171 │ │ │ │ else: │
│ ❱ 172 │ │ │ │ │ y = _reconstruct(x, memo, *rv) │
│ 173 │ │
│ 174 │ # If is its own copy, don't memoize. │
│ 175 │ if y is not x: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:270 in _reconstruct │
│ │
│ 267 │ │
│ 268 │ if state is not None: │
│ 269 │ │ if deep: │
│ ❱ 270 │ │ │ state = deepcopy(state, memo) │
│ 271 │ │ if hasattr(y, '__setstate__'): │
│ 272 │ │ │ y.__setstate__(state) │
│ 273 │ │ else: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:146 in deepcopy │
│ │
│ 143 │ │
│ 144 │ copier = _deepcopy_dispatch.get(cls) │
│ 145 │ if copier is not None: │
│ ❱ 146 │ │ y = copier(x, memo) │
│ 147 │ else: │
│ 148 │ │ if issubclass(cls, type): │
│ 149 │ │ │ y = _deepcopy_atomic(x, memo) │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:230 in _deepcopy_dict │
│ │
│ 227 │ y = {} │
│ 228 │ memo[id(x)] = y │
│ 229 │ for key, value in x.items(): │
│ ❱ 230 │ │ y[deepcopy(key, memo)] = deepcopy(value, memo) │
│ 231 │ return y │
│ 232 d[dict] = _deepcopy_dict │
│ 233 if PyStringMap is not None: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/copy.py:153 in deepcopy │
│ │
│ 150 │ │ else: │
│ 151 │ │ │ copier = getattr(x, "__deepcopy__", None) │
│ 152 │ │ │ if copier is not None: │
│ ❱ 153 │ │ │ │ y = copier(memo) │
│ 154 │ │ │ else: │
│ 155 │ │ │ │ reductor = dispatch_table.get(cls) │
│ 156 │ │ │ │ if reductor: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/torch/_tensor.py:100 in __deepcopy__ │
│ │
│ 97 class Tensor(torch._C._TensorBase): │
│ 98 │ def __deepcopy__(self, memo): │
│ 99 │ │ if has_torch_function_unary(self): │
│ ❱ 100 │ │ │ return handle_torch_function(Tensor.__deepcopy__, (self,), self, memo) │
│ 101 │ │ if not self.is_leaf: │
│ 102 │ │ │ raise RuntimeError( │
│ 103 │ │ │ │ "Only Tensors created explicitly by the user " │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/torch/overrides.py:1534 in │
│ handle_torch_function │
│ │
│ 1531 │ │ │
│ 1532 │ │ # Use `public_api` instead of `implementation` so __torch_function__ │
│ 1533 │ │ # implementations can do equality/identity comparisons. │
│ ❱ 1534 │ │ result = torch_func_method(public_api, types, args, kwargs) │
│ 1535 │ │ │
│ 1536 │ │ if result is not NotImplemented: │
│ 1537 │ │ │ return result │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/torch_core.py:372 in │
│ __torch_function__ │
│ │
│ 369 │ def __torch_function__(cls, func, types, args=(), kwargs=None): │
│ 370 │ │ if cls.debug and func.__name__ not in ('__str__','__repr__'): print(func, types, │
│ 371 │ │ if _torch_handled(args, cls._opt, func): types = (torch.Tensor,) │
│ ❱ 372 │ │ res = super().__torch_function__(func, types, args, ifnone(kwargs, {})) │
│ 373 │ │ dict_objs = _find_args(args) if args else _find_args(list(kwargs.values())) │
│ 374 │ │ if issubclass(type(res),TensorBase) and dict_objs: res.set_meta(dict_objs[0],as_ │
│ 375 │ │ elif dict_objs and is_listy(res): [r.set_meta(dict_objs[0],as_copy=True) for r i │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/torch/_tensor.py:1279 in │
│ __torch_function__ │
│ │
│ 1276 │ │ │ return NotImplemented │
│ 1277 │ │ │
│ 1278 │ │ with _C.DisableTorchFunction(): │
│ ❱ 1279 │ │ │ ret = func(*args, **kwargs) │
│ 1280 │ │ │ if func in get_default_nowrap_functions(): │
│ 1281 │ │ │ │ return ret │
│ 1282 │ │ │ else: │
│ │
│ /home/csaroff/.miniconda3/lib/python3.9/site-packages/torch/_tensor.py:185 in __deepcopy__ │
│ │
│ 182 │ │ │ │ else: │
│ 183 │ │ │ │ │ new_tensor = self.new_empty([]) │
│ 184 │ │ │ │ │ if type(new_tensor) is not type(self): │
│ ❱ 185 │ │ │ │ │ │ raise RuntimeError( │
│ 186 │ │ │ │ │ │ │ "The default implementation of __deepcopy__() for non-wrappe │
│ 187 │ │ │ │ │ │ │ "only works for subclass types that implement new_empty() an │
│ 188 │ │ │ │ │ │ │ "that function returns another instance of the same subclass │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
RuntimeError: Exception occured in `LRFinder` when calling event `before_fit`:
The default implementation of __deepcopy__() for non-wrapper subclasses only works for subclass types that
implement new_empty() and for which that function returns another instance of the same subclass. You should either
properly implement new_empty() for your subclass or override __deepcopy__() if it is intended behavior for
new_empty() to return an instance of a different type.
> /home/csaroff/.miniconda3/lib/python3.9/site-packages/torch/_tensor.py(185)__deepcopy__()
183 new_tensor = self.new_empty([])
184 if type(new_tensor) is not type(self):
--> 185 raise RuntimeError(
186 "The default implementation of __deepcopy__() for non-wrapper subclasses "
187 "only works for subclass types that implement new_empty() and for which "
ipdb> up
> /home/csaroff/.miniconda3/lib/python3.9/site-packages/torch/_tensor.py(1279)__torch_function__()
1277
1278 with _C.DisableTorchFunction():
-> 1279 ret = func(*args, **kwargs)
1280 if func in get_default_nowrap_functions():
1281 return ret
ipdb> up
> /home/csaroff/.miniconda3/lib/python3.9/site-packages/fastai/torch_core.py(372)__torch_function__()
370 if cls.debug and func.__name__ not in ('__str__','__repr__'): print(func, types, args, kwargs)
371 if _torch_handled(args, cls._opt, func): types = (torch.Tensor,)
--> 372 res = super().__torch_function__(func, types, args, ifnone(kwargs, {}))
373 dict_objs = _find_args(args) if args else _find_args(list(kwargs.values()))
374 if issubclass(type(res),TensorBase) and dict_objs: res.set_meta(dict_objs[0],as_copy=True)
ipdb> up
> /home/csaroff/.miniconda3/lib/python3.9/site-packages/torch/overrides.py(1534)handle_torch_function()
1532 # Use `public_api` instead of `implementation` so __torch_function__
1533 # implementations can do equality/identity comparisons.
-> 1534 result = torch_func_method(public_api, types, args, kwargs)
1535
1536 if result is not NotImplemented:
ipdb> p result
*** NameError: name 'result' is not defined
ipdb> up
> /home/csaroff/.miniconda3/lib/python3.9/site-packages/torch/_tensor.py(100)__deepcopy__()
98 def __deepcopy__(self, memo):
99 if has_torch_function_unary(self):
--> 100 return handle_torch_function(Tensor.__deepcopy__, (self,), self, memo)
101 if not self.is_leaf:
102 raise RuntimeError(
ipdb> p self
TensorBase([[[-1., -1.],
[-1., 1.],
[ 1., -1.],
[ 1., 1.]]], device='cuda:0')
ipdb> p self.name
None
ipdb> up
> /home/csaroff/.miniconda3/lib/python3.9/copy.py(153)deepcopy()
151 copier = getattr(x, "__deepcopy__", None)
152 if copier is not None:
--> 153 y = copier(memo)
154 else:
155 reductor = dispatch_table.get(cls)
ipdb> p memo
*** AttributeError: fs
ipdb> p copier
<bound method Tensor.__deepcopy__ of TensorBase([[[-1., -1.],
[-1., 1.],
[ 1., -1.],
[ 1., 1.]]], device='cuda:0')>
ipdb> up
> /home/csaroff/.miniconda3/lib/python3.9/copy.py(230)_deepcopy_dict()
228 memo[id(x)] = y
229 for key, value in x.items():
--> 230 y[deepcopy(key, memo)] = deepcopy(value, memo)
231 return y
232 d[dict] = _deepcopy_dict
ipdb> p key
'targ_pts'
ipdb> p value
TensorBase([[[-1., -1.],
[-1., 1.],
[ 1., -1.],
[ 1., 1.]]], device='cuda:0')
ipdb>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.