# Remote function too large - function size error

**URL:** <https://discuss.ray.io/t/remote-function-too-large-function-size-error/10483>\
**Category:** Ray Clusters\
**Created:** [May 2, 2023, 8:35am UTC](https://discuss.ray.io/t/remote-function-too-large-function-size-error/10483 "2023-05-02T08:35:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![valentina](https://avatars.discourse-cdn.com/v4/letter/v/43a26b/32.png) [@valentina](https://discuss.ray.io/u/valentina)\
**Post date:** [May 2, 2023, 8:35am UTC](https://discuss.ray.io/t/remote-function-too-large-function-size-error/10483/1 "2023-05-02T08:35:06Z")

</div>

Hi,  
I’m new to ray and struggle with the function size restriction.  
“ValueError: The remote function **main**.predict is too large (97 MiB \> FUNCTION\_SIZE\_ERROR\_THRESHOLD=95 MiB).”  
I saw that other people had the same problem and tried to apply the suggested solutions. However, unfortunately I did not manage.  
This is a reduced version of my code:

```auto
# Start Ray cluster
ray.init(num_cpus=num_cpus, ignore_reinit_error=True)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

# val is an array representing an image                                   
ref = ray.put(val) 
@ray.remote                                                                                                     
def predict(ref):
pred = classification_model(ray.get(ref)).softmax(0) # resnet50 model
class_id = preds.argmax().item()

result_refs = []
result_refs.append(predict.remote(ref))
results = ray.get(result_refs)                                                                                                                          

```

My code is supposed to parallelize a pipeline for hundreds of images in the end and this is the core of it.  
Maybe someone knows a solution?  
Cheers!

---

<div class="post-metadata">

**Author:** ![Jules\_Damji](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jules_damji/32/4058_2.png) [@Jules\_Damji](https://discuss.ray.io/u/Jules_Damji)\
**Post date:** [May 2, 2023, 3:25pm UTC](https://discuss.ray.io/t/remote-function-too-large-function-size-error/10483/2 "2023-05-02T15:25:00Z")

</div>

@valentina What’s `classification_model()`? Does it create the instance of the mode each time `predict()` is called?

You might want to put the model into the object store, and send a reference to each task to do the prediction. Notice how in this [tutorial](https://github.com/ray-project/ray-educational-materials/blob/main/Computer_vision_workloads/Semantic_segmentation/Scaling_batch_inference.ipynb) we put images and model in the object store.

---

<div class="post-metadata">

**Author:** ![valentina](https://avatars.discourse-cdn.com/v4/letter/v/43a26b/32.png) [@valentina](https://discuss.ray.io/u/valentina)\
**Post date:** [May 8, 2023, 9:41am UTC](https://discuss.ray.io/t/remote-function-too-large-function-size-error/10483/4 "2023-05-08T09:41:47Z")

</div>

Thank you very much! I was mainly concentrating on the data so I did not think about the model being the problem, works like a charm now.

---

<div class="post-metadata">

**Author:** ![Jules\_Damji](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jules_damji/32/4058_2.png) [@Jules\_Damji](https://discuss.ray.io/u/Jules_Damji)\
**Post date:** [May 10, 2023, 1:01am UTC](https://discuss.ray.io/t/remote-function-too-large-function-size-error/10483/5 "2023-05-10T01:01:03Z")

</div>

Excellent @valentina.
