dotnet / dotnet/machinelearning

Direct Accces to Microsoft.ML.GenAI.LLaMA Model

Aperta
#7,367 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub
area-GenAI enhancement
Lingua principale
C#
Stelle
9.4k
Fork
2k
Merge medio
2g 20h
PR unite (30g)
11

Descrizione

I would like to convert a LLama model to a Multiclass Classification Model and then finetune the model on my classification labels.

Currently, the Microsoft.ML.GenAI.LLaMA/Module/LlamaModel is internal.

Step 1
Load the pre-trained LLaMA model

```
string device = "cpu";
string weightFolder = @".\Llama3.1-8B";
string originalWeightFolder = Path.Combine(weightFolder, "original");
string configName = "config.json";
string modelFile = "tokenizer.model";
string checkPointName = "model.safetensors.index.json";

// Load the Pretrained Model: First, load the pretrained LLaMA model using TorchSharp.
model = LlamaForCausalLM.FromPretrained(weightFolder, configName, checkPointName: checkPointName, layersOnTargetDevice: -1, quantizeToInt8: false, targetDevice: device);

```
Step 2
Create a classification head

```
public class ClassificationHead : Module
{
private readonly Module linear1;
private readonly Module relu;
private readonly Module linear2;

public ClassificationHead(int d_model,int outputSize, int num_classes) : base(nameof(ClassificationHead))
{
linear1 = Linear(d_model, outputSize); // Intermediate layer
relu = ReLU(); // Activation
linear2 = Linear(outputSize, num_classes); // Output layer

RegisterComponents();
}

public override Tensor forward(Tensor x)
{
var output = linear1.forward(x);
output = relu.forward(output);
output = linear2.forward(output);
return output;
}
}
```

step 3
Integrate the classification head into the LLaMA model

This step is not possible to override the Forward Pass: The input is passed through the LLaMA model and then through the classification head to get the output logits.

step 4
Set up the training loop to optimize the model using my data

I intend to use Microsoft.ML.GenAI.Core/Trainer/CasualLMSupervisedFineTuningTrainer

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia leggendo Microsoft.ML.GenAI.LLaMA/Module/LlamaModel e Microsoft.ML.GenAI.Core/Trainer/CasualLMSupervisedFineTuningTrainer. Traccia come viene esposto il modello LLaMA e come il trainer lo utilizza, quindi chiarisci l’accesso pubblico richiesto e l’integrazione del forward pass. Il lavoro è completo quando il percorso di fine-tuning per la classificazione richiesto è definito e supportato dalle API pertinenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
machine-learning
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.