You can optimize a model by randomly changing its weights and validating results on your task. A monkey can type a book given enough attempts.
For training you would need to hook it up to a LoRA training harness, identify the looping weight direction, and adjust the weights accordingly. I've not (yet) looked into how to do this.