Transformers Library issue

I am trying to execute the following code in the server side:

from transformers import pipeline
from transformers import AutoModelForSequenceClassification
from transformers import AutoTokenizer, AutoModelForMaskedLM

MODEL = f"cardiffnlp/twitter-roberta-base-sentiment"
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
model = AutoModelForSequenceClassification.from_pretrained(MODEL)

@anvil.server.callable
def create_pipeline():
  sentiment_pipeline = pipeline("sentiment-analysis", MODEL)

But, I am getting an error:

anvil.server.ExecutionTerminatedError: Server code exited unexpectedly: e8ccc20b1f

The above got runs smoothly when I use the uplink but not in Anvil’s hosted servers.

Is there a way to overcome this issue?

Thanks a lot in advance.

hello, did you ever find a solution to this? currently experiencing the same issue

That’s memory, by the look of it. Generally better to run the big stuff via uplink.

totally but I’m not able to keep an uplink going indefinitely which is what I need for this app. Is there a way to increase the memory or unload some of it somehow?

So, there are a few ways you can approach this: 1) upgrade your plan and get some custom compute.
2) swap out your code for something less intensive.
3) switch out to a third party API and abstract the memory hit
Or
4) set up a lightsail or similar whose job it is purely to run your memory intensive service as an all day uplink.

1 Like

It is a memory related issue.

You can solve this quickly by using uplink in your local computer or ask Anvil support to increase you memory, if applicable.

I would suggest you to choose the first option as is the cheapest with the best performance.

1 Like