Paid with Models: Optimal Contract Design for Collaborative Machine Learning