Bump a semantic model version

EasyMLOps

Why it matters Model registries and serving configs pin versions like this.

Model registries version artifacts with MAJOR.MINOR.PATCH.

Write bump_version(version, part). part is "major", "minor" or "patch". Bumping a part resets the parts to its right to 0. Return the new version string.

Signaturedef bump_version(version, part)

Example

bump_version("1.4.2", "minor") is "1.5.0".

Understand the idea

Model registries often use semantic versions MAJOR.MINOR.PATCH. A patch bump means a small fix, a minor bump means a compatible change, and a major bump means a breaking change, such as new input features. When you bump one part, every part to its right resets to 0. Worked example: from '2.3.9', a patch bump gives '2.3.10' (numbers, not single digits, so 9 becomes 10). A minor bump gives '2.4.0', resetting the patch. A major bump gives '3.0.0', resetting both minor and patch. Rule: split the string on '.', convert the three parts to integers, add 1 to the chosen part, set every part after it to 0, and join back with '.'. Treat the parts as integers, not characters, or '9' plus one becomes a wrong string. Keeping the old patch number after a minor bump is the common bug. Used in: model registries such as MLflow tags, packaging model artifacts, and release pipelines where the version tells serving code whether a model is safe to swap in.

solution.pyPython idle
Ctrl/Cmd + Enter runs sample tests

Run checks the first 2 tests. Submit checks all 4.

  • Sample 1: examplebump_version('1.4.2', 'minor')
  • Sample 2: majorbump_version('1.4.2', 'major')
  • Test 3: patchbump_version('0.9.9', 'patch')
  • Test 4: double digitsbump_version('2.10.3', 'minor')