Lesson 01 - NameError: name '_is_first' is not define

Hi there,

I have setup the Gradient environment per instructed and double checked the fastai library and git pull are the most up-to-date

When I tried to run the cell under “Running Your First Notebook” for Cats and Dogs train in nb “01_intro”, I got the following errors:


NameError Traceback (most recent call last)
in
10 label_func=is_cat, item_tfms=Resize(224))
11
—> 12 learn = cnn_learner(dls, resnet34, metrics=error_rate)
13 learn.fine_tune(1)

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastai/vision/learner.py in cnn_learner(dls, arch, normalize, n_out, pretrained, config, loss_func, opt_func, lr, splitter, cbs, metrics, path, model_dir, wd, wd_bn_bias, train_bn, moms, **kwargs)
178
179 splitter=ifnone(splitter, meta[‘split’])
–> 180 learn = Learner(dls=dls, model=model, loss_func=loss_func, opt_func=opt_func, lr=lr, splitter=splitter, cbs=cbs,
181 metrics=metrics, path=path, model_dir=model_dir, wd=wd, wd_bn_bias=wd_bn_bias, train_bn=train_bn,
182 moms=moms)

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastai/learner.py in init(self, dls, model, loss_func, opt_func, lr, splitter, cbs, metrics, path, model_dir, wd, wd_bn_bias, train_bn, moms)
92 self.training,self.create_mbar,self.logger,self.opt,self.cbs = False,True,print,None,L()
93 self.add_cbs([(cb() if isinstance(cb, type) else cb) for cb in L(defaults.callbacks)+L(cbs)])
—> 94 self(“after_create”)
95
96 @property

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastai/learner.py in call(self, event_name)
131 def ordered_cbs(self, event): return [cb for cb in sort_by_run(self.cbs) if hasattr(cb, event)]
132
–> 133 def call(self, event_name): L(event_name).map(self._call_one)
134
135 def _call_one(self, event_name):

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastcore/foundation.py in map(self, f, gen, *args, **kwargs)
152 def range(cls, a, b=None, step=None): return cls(range_of(a, b=b, step=step))
153
–> 154 def map(self, f, *args, gen=False, **kwargs): return self._new(map_ex(self, f, *args, gen=gen, **kwargs))
155 def argwhere(self, f, negate=False, **kwargs): return self._new(argwhere(self, f, negate, **kwargs))
156 def filter(self, f=noop, negate=False, gen=False, **kwargs):

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastcore/basics.py in map_ex(iterable, f, gen, *args, **kwargs)
654 res = map(g, iterable)
655 if gen: return res
–> 656 return list(res)
657
658 # Cell

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastcore/basics.py in call(self, *args, **kwargs)
644 if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
645 fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
–> 646 return self.func(*fargs, **kwargs)
647
648 # Cell

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastai/learner.py in _call_one(self, event_name)
135 def _call_one(self, event_name):
136 assert hasattr(event, event_name), event_name
–> 137 [cb(event_name) for cb in sort_by_run(self.cbs)]
138
139 def _bn_bias_state(self, with_bias): return norm_bias_params(self.model, with_bias).map(self.opt.state)

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastcore/xtras.py in sort_by_run(fs)
377 while len(inp):
378 for i,o in enumerate(inp):
–> 379 if _is_first(o, inp):
380 res.append(inp.pop(i))
381 break

NameError: name ‘_is_first’ is not defined

Then I switched to Colab and got the exact same error as above. Any clue on this? Thanks!

Can you try again now? This should have been resolved in the latest pip (released < 20 minutes ago)

1 Like

I ran into the same problem as described by the previous user and your updated fastcore 1.3.16 seems not completely resolved the problem. Basically, the error of '_is_first" is not showing up, instead, the “train_loss” ended up in ‘nan’.

hi Muellerzr,

Mine is OK after updated to 1.3.16. Tested on both Gradient and Colab.

Thanks for the fix!

Thanks Rhemac for the info, I found out my problem. It was the cuda 801 error when learn.fine_tune(1) was executed on my laptop and the fix was to add num_workers=0 in ImageDataLoaders.from_name_func according to the solution mentioned in this forum. Thanks muellerzr for the fastcore fix

1 Like