in florence2-VQA/src_serve/score.py [0:0]
def init():
"""
This function is called when the container is initialized/started, typically after create/update of the deployment.
You can write the logic here to perform init operations like caching the model in memory
"""
global model
global processor
# AZUREML_MODEL_DIR is an environment variable created during deployment.
# It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION)
# Please provide your model's folder name if there is one
model_name_or_path = os.path.join(
os.getenv("AZUREML_MODEL_DIR"), "outputs"
)
model_kwargs = dict(
trust_remote_code=True,
revision="refs/pr/6",
device_map=device
)
processor_kwargs = dict(
trust_remote_code=True,
revision="refs/pr/6"
)
model = AutoModelForCausalLM.from_pretrained(model_name_or_path, **model_kwargs)
processor = AutoProcessor.from_pretrained(model_name_or_path, **processor_kwargs)
logging.info("Loaded model.")