question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[CLI]: ValueError by `wandb.log_artifact()` upon logging artifacts that share the same name but different type

See original GitHub issue

Description:

Upon trying to log an artifact (let’s say, artifact_2) of a certain artifact name that shares the same artifact name with a different artifact type, e.g. artifact_1.name='2x5', artifact_1.type='vocabulary', artifact_2.name='2x5', artifact_2.type='model', the wandb.log_artifact() function returns a ValueError due to expecting the same type for artifact_2 as for artifact_1.

The workaround I found for this was to simply use different artifact names for each artifact type, which is slighlty inconvenient as I need to add redundant descriptions. (See in the image attached below, with namings of MODEL/MODEL_2x5 and VOCABLARY/VOCAB_2x5)

I think I know where the error was coming from (as that’s how I managed to figure out a workaround), which is within wandb/apis/public.py. See code snippet of the responsible function below, where the ‘name’ argument seems to be the culprit (I assume, as that’s the only one I have control over as a client when im using wandb.log_artifact()).

    @staticmethod
    def expected_type(client, name, entity_name, project_name):
        """Returns the expected type for a given artifact name and project"""
        query = gql(
            """
        query ArtifactType(
            $entityName: String,
            $projectName: String,
            $name: String!
        ) {
            project(name: $projectName, entityName: $entityName) {
                artifact(name: $name) {
                    artifactType {
                        name
                    }
                }
            }
        }
        """
        )
        if ":" not in name:
            name += ":latest"

        response = client.execute(
            query,
            variable_values={
                "entityName": entity_name,
                "projectName": project_name,
                "name": name,
            },
        )

        project = response.get("project")
        if project is not None:
            artifact = project.get("artifact")
            if artifact is not None:
                artifact_type = artifact.get("artifactType")
                if artifact_type is not None:
                    return artifact_type.get("name")

        return None
Traceback (most recent call last):
  File "train.py", line 279, in <module>
    main()
  File "train.py", line 273, in main
    best_mrr = train(args, train_loader, dev_loader, model, device, best_mrr, model_path, model_folder)
  File "train.py", line 109, in train
    save_folder_wandb(model_folder, artifact_mappings['model'][args.num_neg], ArtifactType.MODEL,
  File "/home/peter/NameMatcher_research/AutoEM/src/utils/serialization.py", line 99, in wrap_arguments_wandb
    return func(file_path, artifact_name, artifact_type, *_, **kwargs)
  File "/home/peter/NameMatcher_research/AutoEM/src/utils/serialization.py", line 72, in wrap_init_wandb
    return func(*args, **kwargs)
  File "/home/peter/NameMatcher_research/AutoEM/src/utils/serialization.py", line 173, in save_folder_wandb
    wandb.log_artifact(artifact)
  File "/home/peter/NameMatcher_research/AutoEM/venv/lib/python3.8/site-packages/wandb/sdk/wandb_run.py", line 222, in wrapper
    return func(self, *args, **kwargs)
  File "/home/peter/NameMatcher_research/AutoEM/venv/lib/python3.8/site-packages/wandb/sdk/wandb_run.py", line 2401, in log_artifact
    return self._log_artifact(
  File "/home/peter/NameMatcher_research/AutoEM/venv/lib/python3.8/site-packages/wandb/sdk/wandb_run.py", line 2538, in _log_artifact
    self._assert_can_log_artifact(artifact)
  File "/home/peter/NameMatcher_research/AutoEM/venv/lib/python3.8/site-packages/wandb/sdk/wandb_run.py", line 2596, in _assert_can_log_artifact
    raise ValueError(
ValueError: Expected artifact type vocabulary, got model

Additional Files

wandb_issue

Environment

WandB version: 0.12.21

OS: Ubuntu 20.04.4 LTS (Focal Fossa)

Python version: 3.8.10

Versions of relevant libraries: -

Additional Context

Please let me know of required label/other modifications in case the issue was assigned a wrong one.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
MBakirWBcommented, Sep 12, 2022

Hi @Peter-Varga08 , the error of wandb.log_artifact() upon logging artifacts that share the same name but different type has been update to Artifact {artifact.name} already exists with type {expected_type}; cannot create another with type {artifact.type}. Thank’s again for writing in with this request. This ticket is now resolved.

1reaction
MBakirWBcommented, Jul 26, 2022

@Peter-Varga08 , thank you for the clarifying remark about your use case and also providing feedback on the error message. I will let eng know and provide an update when available, Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

wandb.Artifact - Documentation - Weights & Biases
Flexible and lightweight building block for dataset and model versioning. ... Constructs an empty artifact whose contents can be populated using its add...
Read more >
Construct artifacts - Documentation - Weights & Biases - Wandb
Artifacts can not have the same name, even if you specify a different type for the types parameter. In other words, you can...
Read more >
Artifacts FAQs - Documentation - Weights & Biases - Wandb
W&B stores artifact files in a way that minimizes duplication across successive artifact versions, as described above. When deleting artifact versions, W&B ...
Read more >
Artifacts - Documentation - Weights & Biases - Wandb
Weights and Biases will create the DAG for you when you use and log artifacts. ... If you create another artifact with the...
Read more >
Artifacts FAQs - Documentation - Weights & Biases - WandB
In other words, it guarantees that the file is not in use by a previous or ... For open projects, all users have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found