Skip to content

Commit

Permalink
don't fail if optim name doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitij12345 committed Jul 27, 2023
1 parent 2c35a8e commit 8a140f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/neptune_fastai/impl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ def _batch_size(self) -> int:

@property
def _optimizer_name(self) -> Optional[str]:
return self.opt_func.__name__
optim_name = getattr(self.opt_func, "__name__", "NA")
warnings.warn("NeptuneCallback: Couldn't retrieve the optimizer name, so it will not be logged.")
return optim_name

@property
def _device(self) -> str:
Expand Down
6 changes: 6 additions & 0 deletions tests/neptune_fastai/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from functools import partial
from itertools import islice
from pathlib import Path

Expand All @@ -24,6 +25,7 @@
untar_data,
)
from fastai.callback.all import SaveModelCallback
from fastai.optimizer import Adam
from fastai.tabular.all import (
Categorify,
FillMissing,
Expand Down Expand Up @@ -71,12 +73,15 @@ def test_vision_classification_with_handler(self):
device=torch.device("cpu"),
)

opt_func = partial(Adam, lr=3e-3, wd=0.01)

learn = cnn_learner(
dls,
squeezenet1_0,
metrics=error_rate,
cbs=[NeptuneCallback(run, "experiment")],
pretrained=False,
opt_func=opt_func,
)

learn.fit(1)
Expand All @@ -91,6 +96,7 @@ def test_vision_classification_with_handler(self):
exp_config = run["experiment/config"].fetch()
assert exp_config["batch_size"] == 64
assert exp_config["criterion"] == "CrossEntropyLoss()"
assert exp_config["optimizer"]["name"] == "NA"
assert exp_config["input_shape"] == {"x": "[3, 224, 224]", "y": 1}

# and
Expand Down

0 comments on commit 8a140f4

Please sign in to comment.