Skip to content

fix: improve version sorting and enhance model export tagging#387

Merged
HenryNdubuaku merged 1 commit intomainfrom
hf_publish_tag
Feb 23, 2026
Merged

fix: improve version sorting and enhance model export tagging#387
HenryNdubuaku merged 1 commit intomainfrom
hf_publish_tag

Conversation

@jakmro
Copy link
Copy Markdown
Collaborator

@jakmro jakmro commented Feb 23, 2026

No description provided.

Copilot AI review requested due to automatic review settings February 23, 2026 05:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request improves version handling in the HuggingFace model publishing workflow by implementing semantic version sorting and refining the tagging logic. The changes ensure that version tags are sorted correctly (e.g., v1.10 comes after v1.9, not before v1.2), and that tags are created atomically with uploads rather than separately.

Changes:

  • Implemented semantic version sorting using tuple-based comparison for proper version ordering
  • Moved tag creation into the conditional block so tags are only created when content is uploaded
  • Removed the delete_patterns parameter from upload operations to preserve historical files
  • Added sys.exit(main()) to properly propagate exit codes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +70 to +74
versions = sorted(
[t.name for t in tags],
key=lambda v: tuple(int(x) for x in v.lstrip("v").split(".")),
reverse=True,
)
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version sorting logic assumes all version tags follow a consistent format with dots separating numeric components (e.g., "v1.2.3"). However, this will raise a ValueError if any tag has a different format (e.g., "v1.2.3-beta", "v1.2", or non-numeric components). Consider adding error handling to gracefully handle malformed version tags, such as wrapping the conversion in a try-except block or filtering out invalid tags.

Suggested change
versions = sorted(
[t.name for t in tags],
key=lambda v: tuple(int(x) for x in v.lstrip("v").split(".")),
reverse=True,
)
valid_versions = []
for tag in tags:
name = tag.name
try:
key = tuple(int(x) for x in name.lstrip("v").split("."))
except ValueError:
# Skip tags that do not conform to the expected numeric version format.
continue
valid_versions.append((name, key))
if not valid_versions:
return None
versions = [name for name, _ in sorted(valid_versions, key=lambda item: item[1], reverse=True)]

Copilot uses AI. Check for mistakes.
exist_ok=True,
)
print("Uploaded and tagged")
else:
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the model hasn't changed (line 192), no tag is created for the current version. This means if the same version is run multiple times without changes, only the first run will create the tag. If the expected behavior is to ensure the tag exists regardless of whether content changed, consider adding an else branch that creates the tag with exist_ok=True even when unchanged. Otherwise, this behavior change (from always tagging to conditional tagging) should be documented or verified as intentional.

Suggested change
else:
else:
api.create_tag(
repo_id=repo_id,
tag=args.version,
revision=api.repo_info(repo_id=repo_id, repo_type="model").sha,
repo_type="model",
tag_message=f"Release {args.version}",
exist_ok=True,
)

Copilot uses AI. Check for mistakes.
@@ -173,20 +178,18 @@ def export_and_publish_model(args, api):
repo_id=repo_id,
repo_type="model",
commit_message=f"Upload {args.version}",
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of delete_patterns=["*"] changes the upload behavior from replacing all files in the repository to appending/updating files. This could lead to stale files accumulating in the repository if file names change between versions. If the intent is to keep all historical files, this is fine. However, if the intent is to have a clean repository with only the latest files, the delete_patterns parameter should be retained or an alternative cleanup strategy should be implemented.

Suggested change
commit_message=f"Upload {args.version}",
commit_message=f"Upload {args.version}",
delete_patterns=["*"],

Copilot uses AI. Check for mistakes.
@HenryNdubuaku HenryNdubuaku merged commit 2137192 into main Feb 23, 2026
5 of 6 checks passed
ncylich pushed a commit that referenced this pull request Feb 24, 2026
cattermelon1234 pushed a commit to cattermelon1234/cactus that referenced this pull request Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants