Skip to main content

Branch

Branching creates a snapshot of an instance and then launches a specified number of new instances from that 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.

Creating Multiple Clones

Branching an instance creates multiple clone instances based on the current state of the original instance.

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)

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

print(f"Snapshot created: {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.