Skip to main content

Branch

Branching launches a specified number of new instances from an instance’s most recent snapshot. This is particularly useful for scenarios where you need multiple identical environments, like parallel testing, training multiple machine learning models, or preparing environments for a team.

If you want to branch the current running state of an instance, create a snapshot first with instance.snapshot(), then branch.

Creating Multiple Clones

Branching an instance creates multiple clone instances based on the instance’s most recent snapshot.

from morphcloud.api import MorphCloudClient

client = MorphCloudClient()

instance_id = "morphvm_abc123" # Replace with a valid instance ID
instance = client.instances.get(instance_id=instance_id)

# (Optional) Capture the current running state before branching
instance.snapshot()

snapshot, clones = instance.branch(count=3)

print(f"Snapshot used for clones: {snapshot.id}")
print("Cloned instances:")
for clone in clones:
print(f" - {clone.id}")

Use Cases for Branching

Branching is particularly useful in the following scenarios:

  1. Parallelized Testing: Create multiple identical environments to run different test suites in parallel.

  2. Machine Learning Training: Branch a prepared environment to train multiple models with different parameters.

  3. Team Development: Create identical environments for each team member from a pre-configured instance.

  4. A/B Deployment Testing: Run the same application with different configurations to test performance or behavior.

  5. Batch Processing: Process different data chunks in parallel with identical processing environments.