code: def rwkv_linear_attention(
      time_decay, time_first, key, value, state=None, return_state=False
  ):
      no_cuda = any(
          t.device.type != "cuda"
          for t in [time_decay, time_first, key, value]
      )
      # Launching the CUDA kernel for just one token will actually be slower (there is no for loop in the CPU version
      # in this case).
      one_token = key.size(1) == 1
      if rwkv_cuda_kernel is None or no_cuda or one_token:
          return rwkv_linear_attention_cpu(
              time_decay,
              time_first,
              key,
              value,
              state=state,
              return_state=return_state,
          )
      else:
          return RwkvLinearAttention.apply(
              time_decay, time_first, key, value, state, return_state
          )
  
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 3 for calling a global function with example usage: rwkv_linear_attention(time_decay, time_first, key, value, state, return_state) and returns: rwkv_linear_attention_cpu, RwkvLinearAttention