Fine-tune sentence transformer model on SageMaker

I am trying to fine-tune a sentence transformer model (specifically ‘sentence-transformers/all-MiniLM-L6-v2’) using AWS SageMaker to later deploy the fine tuned model to an inference endpoint.

I have previously used the sentence_transformers library with InputExamples, losses and SentenceTransformer.fit() for fine-tuning, but now want to move this into a SageMaker training job.

From what I am seeing, I have to create a train.py script that uses the transformers.Trainer.
I have seen multiple versions of the train.py script, but none of which fine-tunes a sentence transformer.

Any example or hint on how to proceed would be much appreciated.