code: def add_deberta_grade(df):
      from transformers import (
          AutoModelForSequenceClassification,
          AutoTokenizer,
      )
      import torch
  
      reward_name = "OpenAssistant/reward-model-deberta-v3-large-v2"
      (
          rank_model,
          tokenizer,
      ) = AutoModelForSequenceClassification.from_pretrained(
          reward_name
      ), AutoTokenizer.from_pretrained(
          reward_name
      )
      device = "cuda" if torch.cuda.is_available() else "cpu"
      rank_model.to(device)
  
      def get_question(x):
          return x.replace("<human>: ", "").split("<bot>:")[0]
  
      def get_answer(x):
          try:
              answer = (
                  x.split("<bot>: ")[1]
                  .split("<human>:")[0]
                  .replace("<bot>: ", "")
              )
          except:
              answer = (
                  x.split("<bot>:")[1]
                  .split("<human>:")[0]
                  .replace("<bot>:", "")
              )
          return answer
  
      df["question"] = parallel_apply(
          df["text"], get_question, n_jobs=-1
      )
      df["answer"] = parallel_apply(df["text"], get_answer, n_jobs=-1)
  
      from datasets import Dataset
      from transformers import pipeline
      from transformers.pipelines.pt_utils import KeyPairDataset
      import tqdm
  
      pipe = pipeline(
          "text-classification",
          model=reward_name,
          device="cuda:0" if torch.cuda.is_available() else "cpu",
      )
      start = 0
      batch_size = 64 * 16
      micro_batch = orig_micro_batch = 16
      end = 0
      import socket
  
      checkpoint = "grades.%s.pkl" % socket.gethostname()
      grades = []
      import pickle
  
      if os.path.exists(checkpoint):
          with open(checkpoint, "rb") as f:
              start, grades = pickle.loads(f.read())
      last_oom = 0
      while end < df.shape[0]:
          # manual batching to handle OOM more gracefully
          end = min(start + batch_size, df.shape[0])
          if start == end:
              break
          dataset = Dataset.from_pandas(df.iloc[start:end, :])
          try:
              grades.extend(
                  [
                      x["score"]
                      for x in tqdm.tqdm(
                          pipe(
                              KeyPairDataset(
                                  dataset, "question", "answer"
                              ),
                              batch_size=micro_batch,
                          )
                      )
                  ]
              )
          except torch.cuda.OutOfMemoryError:
              last_oom = start
              micro_batch = max(1, micro_batch // 2)
              print("OOM - retrying with micro_batch=%d" % micro_batch)
              continue
          if last_oom == start:
              micro_batch = orig_micro_batch
              print("Returning to micro_batch=%d" % micro_batch)
          assert len(grades) == end
          start = end
          with open(checkpoint, "wb") as f:
              f.write(pickle.dumps((end, grades)))
          print("%d/%d" % (end, df.shape[0]))
      df["grade_deberta"] = grades
      if os.path.exists(checkpoint):
          os.remove(checkpoint)
      return df
  
imports: import ast
  import concurrent.futures
  import contextlib
  import hashlib
  import json
  import os
  import shutil
  import signal
  import sys
  import traceback
  from concurrent.futures import ProcessPoolExecutor
  import psutil
  import pytest
  import pandas
  import numpy
  from tqdm import tqdm
  from utils import flatten_list, remove
  from joblib import Parallel, delayed, effective_n_jobs
  from sklearn.utils import gen_even_slices
  from sklearn.utils.validation import _num_samples
label_desc: Use image node_id 28 for calling a global function with example usage: add_deberta_grade(df) and returns: df, x, answer