How to disable Neptune callback in transformers trainer runs?

How to disable Neptune callback in transformers trainer runs?

Problem Description:

After installing Neptune.ai for occasional ML experiments logging, it became included by default into the list of callbacks in all transformers.trainer runs. As a result, it requires proper initialisation with token or else throws NeptuneMissingConfiguration error, demanding token and project name.
This is really annoying, I’d prefer Neptune callback to limit itself to warning or just have it disabled if no token is provided.
Unfortunately there is no obvious way to disable this callback, short of uninstalling Neptune.ai altogether. The doc page at https://huggingface.co/docs/transformers/main_classes/callback states that this callback is enabled by default and gives no way to disable it (unlike some other callbacks that can be disabled by environment variable).

Question: how to disable Neptune callback on per run basis?

Solution – 1

To disable Neptune callback in transformers trainer runs, you can pass the –no-neptune flag to the trainer.train() function.

trainer = Trainer(
    model=model,
    args=args,
    train_dataset=train_dataset,
    eval_dataset=eval_dataset,
    no_neptune=True
)
trainer.train()

Solution – 2

Apparently this piece of code after trainer initialization helps:

for cb in trainer.callback_handler.callbacks:
    if isinstance(cb, transformers.integrations.NeptuneCallback):
        trainer.callback_handler.remove_callback(cb)

Still it would be good if Transformers or Neptune team provided more flexibility with this callback.

Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject