# Minimizing models loading / offloading

**URL:** <https://discuss.ray.io/t/minimizing-models-loading-offloading/23512>\
**Category:** Uncategorized\
**Created:** [April 20, 2026, 2:42pm UTC](https://discuss.ray.io/t/minimizing-models-loading-offloading/23512 "2026-04-20T14:42:09Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![RunLLM](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/runllm/32/8249_2.png) [@RunLLM](https://discuss.ray.io/u/RunLLM)\
**Post date:** [April 21, 2026, 1:15pm UTC](https://discuss.ray.io/t/minimizing-models-loading-offloading/23512/6 "2026-04-21T13:15:10Z")

</div>

Certainly! Here’s a simple example of manual orchestration: you check available resources, then decide whether to run both actors (models) in parallel or serialize them to minimize model loading/offloading. This pattern is not automatic in Ray; you must implement the logic yourself ([see this example](https://discuss.ray.io/t/sharing-big-ml-models-using-only-ray-core/6745), [Ray resource scheduling](https://docs.anyscale.com/get-started/ray-basics.md)).

```python
import ray
import time

ray.init()

@ray.remote
class ModelActor:
    def __init__ (self, model_name):
        print(f"Loading model {model_name}")
        self.model_name = model_name
        time.sleep(2) # Simulate model loading

    def run_task(self, x):
        return f"{self.model_name} processed {x}"

def run_tasks_serial():
    # Run all A tasks with model M1
    actor_a = ModelActor.remote("M1")
    results_a = ray.get([actor_a.run_task.remote(i) for i in range(5)])
    ray.kill(actor_a)
    # Run all B tasks with model M2
    actor_b = ModelActor.remote("M2")
    results_b = ray.get([actor_b.run_task.remote(i) for i in range(5, 10)])
    ray.kill(actor_b)
    return results_a + results_b

def run_tasks_parallel():
    actor_a = ModelActor.remote("M1")
    actor_b = ModelActor.remote("M2")
    results_a = [actor_a.run_task.remote(i) for i in range(5)]
    results_b = [actor_b.run_task.remote(i) for i in range(5, 10)]
    results = ray.get(results_a + results_b)
    ray.kill(actor_a)
    ray.kill(actor_b)
    return results

# Example: check available resources and choose strategy
resources = ray.available_resources()
if resources.get("CPU", 0) >= 2:
    print("Running in parallel")
    results = run_tasks_parallel()
else:
    print("Running serially")
    results = run_tasks_serial()

print(results)

```

This code checks available CPUs and chooses whether to run both actors in parallel or serialize them, minimizing model loads if resources are limited.

Sources:

- [see this example](https://discuss.ray.io/t/sharing-big-ml-models-using-only-ray-core/6745)

Hint: Mention @RunLLM in the post for followups.

---

_[View the full topic](https://discuss.ray.io/t/minimizing-models-loading-offloading/23512)._
