Answers.Body: <p>After your forward pass, you can always just use the logits and calculate the loss yourself. In this case, you'd only use the loss on the last input token.</p>
  <p>Huggingface also has a LlamaForSequenceClassification class, which does exactly this.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-16T05:05:32.557Z
Answers.LastActivityDate: 2023-07-16T05:05:32.557Z
Answers.UserDisplayName: Alexander Wan
Body: <p>I am trying to fine-tune Llama model on two task at the same time, using hugging face library:</p>
  <p>Main task: Causal language model like the model was initially trained for
  A classification task based on the whole input sequence (recommend an article). For this task I am getting as a reference the LlamaForCausalLM class, overwriting init and forward functions .
  However, I want to combine the two tasks above into one process. The main problem is that language modelling is an iterative process were the loss is calculated for every new context token in the input sequence, while for the classification task the loss should only be calculated once.</p>
  <p>How can I freeze the loss update on the classification task up and only calculated once the language modelling part has been completed. Is there any example you can recommend in order to combine a main LM task with an auxiliary classification task?</p>
  <p>First question for me here, thanks everyone for your understanding.</p>
  
Tags: <deep-learning><natural-language-processing><large-language-models>
Title: Fine-Tune Llama on main and auxiliary task
UserDisplayName: Dimits
ThreadText: # Fine-Tune Llama on main and auxiliary task
  
  (Asked by: username_0 on 2023-07-15)
  
  I am trying to fine-tune Llama model on two task at the same time, using hugging face library:
  
  Main task: Causal language model like the model was initially trained for
  A classification task based on the whole input sequence (recommend an article). For this task I am getting as a reference the LlamaForCausalLM class, overwriting init and forward functions .
  However, I want to combine the two tasks above into one process. The main problem is that language modelling is an iterative process were the loss is calculated for every new context token in the input sequence, while for the classification task the loss should only be calculated once.
  
  How can I freeze the loss update on the classification task up and only calculated once the language modelling part has been completed. Is there any example you can recommend in order to combine a main LM task with an auxiliary classification task?
  
  First question for me here, thanks everyone for your understanding.
  
  **Tags:** deep-learning, natural-language-processing, large-language-models
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-07-16. Score: 0
  
  After your forward pass, you can always just use the logits and calculate the loss yourself. In this case, you'd only use the loss on the last input token.
  
  Huggingface also has a LlamaForSequenceClassification class, which does exactly this.
  
  
  ---
  
  