Skip to content

eval_on_start triggers AttributeError in JupyterLab #32689

@matteosantama

Description

@matteosantama

System Info

transformers: '4.44.0'
Python: '3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:45:18) [GCC 12.3.0]'

Who can help?

@muellerz @SunMarc

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

Here is a self-contained script that triggers the error:

model_id = "distilbert/distilbert-base-uncased"

model = AutoModelForSequenceClassification.from_pretrained(
    model_id, num_labels=2
)
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=True)

ds = (
    Dataset.from_dict({"text": ["Hello world!"], "labels": [0]})
    .map(
        lambda b: tokenizer(b["text"], truncation=True),
        batched=True,
    )
)


trainer = Trainer(
    model=model,
    args=TrainingArguments(
        output_dir="temp",
        eval_strategy="steps",
        save_strategy="no",
        eval_on_start=True,  # <-- setting to False avoids the error
    ),
    tokenizer=tokenizer,
    train_dataset=ds,
    eval_dataset=ds,
    compute_metrics=lambda _: {"metric": 1.0},
)
trainer.train()

The error I get is

AttributeError: 'NotebookTrainingTracker' object has no attribute 'value'

which seems related to the fact that I'm running the code in a Jupyter notebook.

Expected behavior

I should be able to use the eval_on_start parameter without triggering an error.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions