class_docstr:     Data collator used for completion tasks. It ensures that all the tokens of the labels are set to an 'ignore_index'
      when they do not come from the assistant. This ensure that the loss is only
      calculated on the completion made by the assistant.
  
      Args:
          response_template (`Union[str, List[int]]`): the template form that indicates the start of the response, typically something like
              '### Response:
  '. It can also be passed as tokenized ids, which can be useful when using a tokenizer that encodes the response
              differently if it does not have proper context.
          instruction_template (`Union[str, List[int]]`): the template form that indicates the start of the human instruction, typically something like
              '### Human:
  '. Useful for assistant-style conversation datasets. It can also be passed as tokenized ids.
          mlm (`bool`, *optional*, defaults to `False`): Whether or not to use masked language modeling in the underlying
              `DataCollatorForLanguageModeling` class. Note that this option currently has no effect but is present
               for flexibility and backwards-compatibility.
          ignore_index (`int`, *optional*, defaults to `-100`):
              The index to use to ignore the initial tokens with
      
class_docstr_tok: ["Data","collator","used","for","completion","tasks",".","It","ensures","that","all","the","tokens","of","the","labels","are","set","to","an","'ignore_index'","when","they","do","not","come","from","the","assistant",".","This","ensure","that","the","loss","is","only","calculated","on","the","completion","made","by","the","assistant",".","Args",":","response_template","(","`","Union","[","str",",","List","[","int","]","]","`",")",":","the","template","form","that","indicates","the","start","of","the","response",",","typically","something","like","'","#","#","#","Response",":","'",".","It","can","also","be","passed","as","tokenized","ids",",","which","can","be","useful","when","using","a","tokenizer","that","encodes","the","response","differently","if","it","does","not","have","proper","context",".","instruction_template","(","`","Union","[","str",",","List","[","int","]","]","`",")",":","the","template","form","that","indicates","the","start","of","the","human","instruction",",","typically","something","like","'","#","#","#","Human",":","'",".","Useful","for","assistant-style","conversation","datasets",".","It","can","also","be","passed","as","tokenized","ids",".","mlm","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","or","not","to","use","masked","language","modeling","in","the","underlying","`","DataCollatorForLanguageModeling","`","class",".","Note","that","this","option","currently","has","no","effect","but","is","present","for","flexibility","and","backwards-compatibility",".","ignore_index","(","`","int","`",",","*","optional","*",",","defaults","to","`","-100","`",")",":","The","index","to","use","to","ignore","the","initial","tokens","with"]
code: def __init__(
      self,
      response_template: Union[str, List[int]],
      instruction_template: Union[str, List[int]] = None,
      *args,
      mlm: bool = False,
      ignore_index: int = -100,
      **kwargs,
  ):
      super().__init__(*args, mlm=mlm, **kwargs)
  
      self.instruction_template = instruction_template
      if isinstance(instruction_template, str):
          # The user provides a string, must tokenize
          self.instruction_token_ids = self.tokenizer.encode(
              self.instruction_template, add_special_tokens=False
          )
      else:
          # The user already provides the token ids
          self.instruction_token_ids = instruction_template
  
      self.response_template = response_template
      if isinstance(response_template, str):
          # The user provides a string, must tokenize
          self.response_token_ids = self.tokenizer.encode(
              self.response_template, add_special_tokens=False
          )
      else:
          # The user already provides the token ids
          self.response_token_ids = response_template
  
      if (
          not self.mlm
          and self.instruction_template
          and self.tokenizer.pad_token_id == self.tokenizer.eos_token_id
      ):
          warnings.warn(
              "The pad_token_id and eos_token_id values of this tokenizer are identical. "
              "If you are planning for multi-turn training, "
              "it can result in the model continuously generating questions and answers without eos token. "
              "To avoid this, set the pad_token_id to a different value."
          )
  
      self.ignore_index = ignore_index
  
imports: import random
  import warnings
  from collections import deque
  from dataclasses import dataclass
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  from torch.nn.utils.rnn import pad_sequence
  from torch.utils.data import IterableDataset
  from transformers import DataCollatorForLanguageModeling, PreTrainedTokenizerBase
  from ..import_utils import is_unsloth_available
label_desc: Use image node_id 1 to create a new DataCollatorForCompletionOnlyLM object from inherited base classes: DataCollatorForLanguageModeling with example: obj = DataCollatorForCompletionOnlyLM(response_template, instruction_template)