LocalAI icon indicating copy to clipboard operation
LocalAI copied to clipboard

feature: fine-tuning endpoint

Open mudler opened this issue 3 years ago • 8 comments

Is your feature request related to a problem? Please describe.

Describe the solution you'd like

Describe alternatives you've considered

Additional context

mudler avatar Jun 14 '23 14:06 mudler

Regarding the feature request for fine-tuning endpoint:

Description: Implement a fine-tuning endpoint in the existing system that allows users to fine-tune the AI model based on their specific needs and data.

Objective: Enable users to customize the AI model's behavior, improving its performance in their domain or specialized tasks.

Implementation: Create an API endpoint where users can upload their dataset and provide parameters to fine-tune the model. The system should then fine-tune the AI model and provide a downloadable version for the user.

Benefits: This feature enhances the adaptability of the AI system, making it more versatile and applicable to a wider range of real-world use cases.

Example: A healthcare company can fine-tune the model to better understand medical records, improving accuracy and relevance in medical-related queries.

Reference: Refer to similar functionalities in popular AI frameworks like Hugging Face's Transformers library, which allows fine-tuning models for various NLP tasks.

Giancarlo1974 avatar Oct 01 '23 10:10 Giancarlo1974

Hi @mudler, I’ve been working on the issue now.

My approach is:

  • Schema (core/schema/finetuning.go): OpenAI-compatible types for jobs, events, hyperparams, file usage.
  • Service (core/services/finetuning.go): In-memory job store (xsync.SyncedMap), dataset upload + JSONL validation, CRUD for jobs; training is a stub (noOpTrainer).
  • HTTP (core/http/endpoints/openai/finetuning.go): Handlers for create/list/get/cancel jobs and get result file under /v1/fine_tuning/.
  • Wiring: Service in application.go, routes in core/http/routes/openai.go.

Real training backend and model artifacts are not implemented yet. I’d appreciate it if you could review the approach (schema, service, and HTTP handlers) before I open a PR, so I can align with your expectations. Thanks.

mkdev5 avatar Feb 04 '26 19:02 mkdev5

any update for me? @mudler

mkdev5 avatar Feb 05 '26 20:02 mkdev5

@MkDev11 the approach sounds reasonable, however without an e2e backend which would handle fine-tuning this is a no-go for me. The rationale is to not introduce dead or unused code in the codebase. Maybe we can start with a specific backend (for instance, unsloth?) that exposes a basic gRPC api which could be extended in the future

mudler avatar Feb 06 '26 13:02 mudler

@mudler Thanks for the clarification — agreed on avoiding dead code, and I’m on board with starting from a real backend and a small gRPC API.

Plan:

  1. Backend: A dedicated fine-tuning backend (e.g. Python) that wraps Unsloth (no built-in gRPC today — we’d add a thin gRPC server on top of its Python API). It would run training end-to-end and expose the results (e.g. adapter or model path/artifact).

  2. gRPC surface (proposal): A minimal proto separate from the existing inference backends, e.g.:

    • CreateJob(model_id, dataset_path, hyperparams) → job_id
    • GetJobStatus(job_id) → status, progress, error_message
    • CancelJob(job_id) → ok
    • GetArtifacts(job_id) → artifact_path(s) or download So the current HTTP layer in LocalAI would only call this backend when one is configured (no unused code path).
  3. Next step: I’ll draft the proto and a short design (where it lives, how LocalAI discovers/configures the fine-tuning backend) and post it here for review. Once that’s agreed, I’ll implement the Unsloth-backed service and wire it from LocalAI.

Two questions so I can align with your preferences:

  • Is Unsloth the backend you’d like to start with, or would you prefer another (e.g. Axolotl, LLM-Foundry)?
  • Should the fine-tuning proto and backend live in this repo (e.g. under something like backend/finetuning-unsloth/) or in a separate repo?

mkdev5 avatar Feb 06 '26 16:02 mkdev5

@mudler any update for me?

mkdev5 avatar Feb 15 '26 13:02 mkdev5

This is now part of the core - we have to extend support to other backends, and improve the current implementation which is experimental

mudler avatar Apr 10 '26 09:04 mudler