[CLI]: ValueError by `wandb.log_artifact()` upon logging artifacts that share the same name but different type
See original GitHub issueDescription:
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

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:
- Created a year ago
- Comments:5

Top Related StackOverflow Question
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.@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!