code: def serve_request(self, raw_request: Dict[str, Any]):
      encoded_input = self.tokenizer(
          raw_request["prompt"], return_tensors="pt"
      ).to(self.device)
      raw_request = deepcopy(raw_request)
      raw_request["do_sample"] = True
      raw_request["return_dict_in_generate"] = True
      raw_request["output_scores"] = True
      top_k_per_token: int = raw_request["top_k_per_token"]
      del raw_request["top_k_per_token"]
      if len(raw_request["stop_sequences"]) > 0:
          stop_sequence_ids = self.tokenizer(
              raw_request["stop_sequences"]
          )
          # Total number of stop words should be 1.
          assert len(stop_sequence_ids.input_ids) == 1
          # Total number of tokens in each stop word should be 1.
          assert len(stop_sequence_ids.input_ids[0]) == 1
          del raw_request["stop_sequences"]
          raw_request["eos_token_id"] = stop_sequence_ids.input_ids[0][
              0
          ]
  
      # Strip out irrelevant parameters
      relevant_raw_request = {
          key: raw_request[key]
          for key in raw_request
          if key
          not in ["engine", "prompt", "echo_prompt", "stop_sequences"]
      }
  
      # Use HuggingFace's `generate` method.
      output = self.model.generate(
          **encoded_input, **relevant_raw_request
      )
      sequences = output.sequences
      scores = output.scores
  
      # Compute logprobs for each completed sequence.
      all_logprobs_of_chosen_tokens = []
      all_top_logprobs_dicts = []
      for completion_id in range(raw_request["num_return_sequences"]):
          logprobs_of_chosen_tokens = []
          top_logprobs_dicts = []
          for i in range(
              len(sequences[completion_id])
              - len(encoded_input.input_ids[0])
          ):
              logprobs = torch.nn.functional.log_softmax(
                  scores[i][completion_id], dim=0
              )
  
              # Get top tokens in terms of log probability.
              topk_logprobs = torch.topk(logprobs, k=top_k_per_token)
              top_logprobs_dicts.append(
                  {
                      self.tokenizer.convert_ids_to_tokens(
                          k.item()
                      ): v.item()
                      for (k, v) in zip(
                          topk_logprobs.indices, topk_logprobs.values
                      )
                  }
              )
  
              # Get log probability of chosen token.
              j = i + len(encoded_input.input_ids[0])
              logprobs_of_chosen_tokens.append(
                  logprobs[sequences[completion_id][j]].item()
              )
          all_logprobs_of_chosen_tokens.append(
              logprobs_of_chosen_tokens
          )
          all_top_logprobs_dicts.append(top_logprobs_dicts)
  
      # Remove prompt from the start of each sequence if echo_prompt is False.
      if not raw_request["echo_prompt"]:
          sequences = [
              sequence[len(encoded_input.input_ids[0]) :]
              for sequence in sequences
          ]
  
      # TODO: Get rid of the extra tokenization?
      all_tokens = [
          self.tokenizer.convert_ids_to_tokens(sequence)
          for sequence in sequences
      ]
      all_decoded_text = self.tokenizer.batch_decode(sequences)
  
      completions = []
      for (
          decoded_text,
          tokens,
          logprobs_of_chosen_tokens,
          top_logprobs_dicts,
      ) in zip(
          all_decoded_text,
          all_tokens,
          all_logprobs_of_chosen_tokens,
          all_top_logprobs_dicts,
      ):
          completions.append(
              {
                  "text": decoded_text,
                  "tokens": tokens,
                  "logprobs": logprobs_of_chosen_tokens,
                  "top_logprobs_dicts": top_logprobs_dicts,
              }
          )
  
      return {
          "completions": completions,
          "input_length": len(encoded_input.input_ids[0]),
      }
  
imports: from copy import deepcopy
  import torch
  from dataclasses import asdict
  from transformers import AutoModelForCausalLM, AutoTokenizer
  from typing import Any, Dict, List
  from helm.common.cache import Cache, CacheConfig
  from helm.common.hierarchical_logger import htrack_block, hlog
  from helm.common.request import EMBEDDING_UNAVAILABLE_REQUEST_RESULT, Request, RequestResult, Sequence, Token
  from helm.common.tokenization_request import TokenizationRequest, TokenizationRequestResult, DecodeRequest, DecodeRequestResult, TokenizationToken
  from .client import Client, wrap_request_time, truncate_sequence
  from .huggingface_tokenizer import HuggingFaceTokenizers
  from helm.proxy.clients.huggingface_model_registry import HuggingFaceModelConfig, get_huggingface_model_config
label_desc: Use image node_id 2 for calling the HuggingFaceServer obj's underlying member method code with example usage: obj.serve_request(raw_request) and returns: dict