docstr: labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
      Labels for language modeling. Note that the labels **are shifted** inside the model, i.e. you can set
      `labels = input_ids` Indices are selected in `[-100, 0, ..., config.vocab_size]` All labels set to `-100`
      are ignored (masked), the loss is only computed for labels in `[0, ..., config.vocab_size]`
docstr_tok: ["labels","(","`","torch.LongTensor","`","of","shape","`","(","batch_size",",","sequence_length",")","`",",","*","optional","*",")",":","Labels","for","language","modeling",".","Note","that","the","labels","*","*","are","shifted","*","*","inside","the","model",",","i.e",".","you","can","set","`","labels","=","input_ids","`","Indices","are","selected","in","`","[","-100",",","0",",","...",",","config.vocab_size","]","`","All","labels","set","to","`","-100","`","are","ignored","(","masked",")",",","the","loss","is","only","computed","for","labels","in","`","[","0",",","...",",","config.vocab_size","]","`"]
code: def forward(
      self,
      input_ids: Optional[torch.LongTensor] = None,
      attention_mask: Optional[torch.LongTensor] = None,  # noqa
      inputs_embeds: Optional[torch.FloatTensor] = None,
      state: Optional[List[torch.FloatTensor]] = None,
      labels: Optional[torch.LongTensor] = None,
      use_cache: Optional[bool] = None,
      output_attentions: Optional[bool] = None,
      output_hidden_states: Optional[bool] = None,
      return_dict: Optional[bool] = None,
  ) -> Union[Tuple, RwkvCausalLMOutput]:
      r"""
      labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
          Labels for language modeling. Note that the labels **are shifted** inside the model, i.e. you can set
          `labels = input_ids` Indices are selected in `[-100, 0, ..., config.vocab_size]` All labels set to `-100`
          are ignored (masked), the loss is only computed for labels in `[0, ..., config.vocab_size]`
      """
      return_dict = (
          return_dict
          if return_dict is not None
          else self.config.use_return_dict
      )
  
      rwkv_outputs = self.rwkv(
          input_ids,
          inputs_embeds=inputs_embeds,
          state=state,
          use_cache=use_cache,
          output_attentions=output_attentions,
          output_hidden_states=output_hidden_states,
          return_dict=return_dict,
      )
      hidden_states = rwkv_outputs[0]
  
      logits = self.head(hidden_states)
  
      loss = None
      if labels is not None:
          # move labels to correct device to enable model parallelism
          labels = labels.to(logits.device)
          # Shift so that tokens < n predict n
          shift_logits = logits[..., :-1, :].contiguous()
          shift_labels = labels[..., 1:].contiguous()
          # Flatten the tokens
          loss_fct = CrossEntropyLoss()
          loss = loss_fct(
              shift_logits.view(-1, shift_logits.size(-1)),
              shift_labels.view(-1),
          )
  
      if not return_dict:
          output = (logits,) + rwkv_outputs[1:]
          return ((loss,) + output) if loss is not None else output
  
      return RwkvCausalLMOutput(
          loss=loss,
          logits=logits,
          state=rwkv_outputs.state,
          hidden_states=rwkv_outputs.hidden_states,
          attentions=rwkv_outputs.attentions,
      )
  
imports: import math
  from dataclasses import dataclass
  from pathlib import Path
  from typing import List, Optional, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from torch.nn import CrossEntropyLoss
  from ...modeling_utils import PreTrainedModel
  from ...utils import ModelOutput, add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, is_bitsandbytes_available, is_ninja_available, is_torch_cuda_available, logging
  from .configuration_rwkv import RwkvConfig
label_desc: Use image node_id 5 for calling the RwkvForCausalLM obj's underlying member method code with example usage: obj.forward(input_ids, attention_mask, inputs_embeds, state, labels, use_cache, output_attentions, output_hidden_states, return_dict) and returns: RwkvCausalLMOutput, unknown