prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Error for SPLADE on-the-fly encoding with pytorch  
  command used:
  ```bash
  python -m pyserini.search.lucene --threads 12 --batch-size 128 \
    --index msmarco-v1-passage-splade-pp-ed \
    --topics msmarco-passage-dev-subset \
    --encoder naver/splade-cocondenser-ensembledistil \
    --output run.msmarco-v1-passage.splade-pp-ed-pytorch.dev.txt \
    --hits 1000 --impact
  ```
  
  error message:
  > ...
  >   File "/home/arthur/workplace/pyserini/pyserini/encode/_splade.py", line 28, in encode
  >     raw_weights = self._output_to_weight_dicts(batch_token_ids, batch_weights)
  > NameError: name 'batch_token_ids' is not defined
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pyserini/encode/_splade.py`
  Content:
  ```
  1 import torch
  2 from transformers import AutoModelForMaskedLM, AutoTokenizer
  3 import numpy as np
  4 
  5 from pyserini.encode import QueryEncoder
  6 
  7 
  8 class SpladeQueryEncoder(QueryEncoder):
  9     def __init__(self, model_name_or_path, tokenizer_name=None, device='cpu'):
  10         self.device = device
  11         self.model = AutoModelForMaskedLM.from_pretrained(model_name_or_path)
  12         self.model.to(self.device)
  13         self.tokenizer = AutoTokenizer.from_pretrained(tokenizer_name or model_name_or_path)
  14         self.reverse_voc = {v: k for k, v in self.tokenizer.vocab.items()}
  15         self.weight_range = 5
  16         self.quant_range = 256
  17 
  18     def encode(self, text, max_length=256, **kwargs):
  19         inputs = self.tokenizer([text], max_length=max_length, padding='longest',
  20                                 truncation=True, add_special_tokens=True,
  21                                 return_tensors='pt').to(self.device)
  22         input_ids = inputs['input_ids']
  23         input_attention = inputs['attention_mask']
  24         batch_logits = self.model(input_ids)['logits']
  25         batch_aggregated_logits, _ = torch.max(torch.log(1 + torch.relu(batch_logits))
  26                                                * input_attention.unsqueeze(-1), dim=1)
  27         batch_aggregated_logits = batch_aggregated_logits.cpu().detach().numpy()
  28         raw_weights = self._output_to_weight_dicts(batch_token_ids, batch_weights)
  29         return self._get_encoded_query_token_wight_dicts(raw_weights)[0]
  30 
  31     def _output_to_weight_dicts(self, batch_aggregated_logits):
  32         to_return = []
  33         for aggregated_logits in batch_aggregated_logits:
  34             col = np.nonzero(aggregated_logits)[0]
  35             weights = aggregated_logits[col]
  36             d = {self.reverse_voc[k]: float(v) for k, v in zip(list(col), list(weights))}
  37             to_return.append(d)
  38         return to_return
  39 
  40     def _get_encoded_query_token_wight_dicts(self, tok_weights):
  41         to_return = []
  42         for _tok_weight in tok_weights:
  43             _weights = {}
  44             for token, weight in _tok_weight.items():
  45                 weight_quanted = round(weight / self.weight_range * self.quant_range)
  46                 _weights[token] = weight_quanted
  47             to_return.append(_weights)
  48         return to_return
  49
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pyserini/encode/_splade.py b/pyserini/encode/_splade.py
  --- a/pyserini/encode/_splade.py
  +++ b/pyserini/encode/_splade.py
  @@ -25,7 +25,7 @@
           batch_aggregated_logits, _ = torch.max(torch.log(1 + torch.relu(batch_logits))
                                                  * input_attention.unsqueeze(-1), dim=1)
           batch_aggregated_logits = batch_aggregated_logits.cpu().detach().numpy()
  -        raw_weights = self._output_to_weight_dicts(batch_token_ids, batch_weights)
  +        raw_weights = self._output_to_weight_dicts(batch_aggregated_logits)
           return self._get_encoded_query_token_wight_dicts(raw_weights)[0]
   
       def _output_to_weight_dicts(self, batch_aggregated_logits):
  
verification_info: {"golden_diff": "diff --git a/pyserini/encode/_splade.py b/pyserini/encode/_splade.py\n--- a/pyserini/encode/_splade.py\n+++ b/pyserini/encode/_splade.py\n@@ -25,7 +25,7 @@\n         batch_aggregated_logits, _ = torch.max(torch.log(1 + torch.relu(batch_logits))\n                                                * input_attention.unsqueeze(-1), dim=1)\n         batch_aggregated_logits = batch_aggregated_logits.cpu().detach().numpy()\n-        raw_weights = self._output_to_weight_dicts(batch_token_ids, batch_weights)\n+        raw_weights = self._output_to_weight_dicts(batch_aggregated_logits)\n         return self._get_encoded_query_token_wight_dicts(raw_weights)[0]\n \n     def _output_to_weight_dicts(self, batch_aggregated_logits):\n", "issue": "Error for SPLADE on-the-fly encoding with pytorch  \ncommand used:\r\n```bash\r\npython -m pyserini.search.lucene --threads 12 --batch-size 128 \\\r\n  --index msmarco-v1-passage-splade-pp-ed \\\r\n  --topics msmarco-passage-dev-subset \\\r\n  --encoder naver/splade-cocondenser-ensembledistil \\\r\n  --output run.msmarco-v1-passage.splade-pp-ed-pytorch.dev.txt \\\r\n  --hits 1000 --impact\r\n```\r\n\r\nerror message:\r\n> ...\r\n>   File \"/home/arthur/workplace/pyserini/pyserini/encode/_splade.py\", line 28, in encode\r\n>     raw_weights = self._output_to_weight_dicts(batch_token_ids, batch_weights)\r\n> NameError: name 'batch_token_ids' is not defined\r\n\n", "before_files": [{"content": "import torch\nfrom transformers import AutoModelForMaskedLM, AutoTokenizer\nimport numpy as np\n\nfrom pyserini.encode import QueryEncoder\n\n\nclass SpladeQueryEncoder(QueryEncoder):\n    def __init__(self, model_name_or_path, tokenizer_name=None, device='cpu'):\n        self.device = device\n        self.model = AutoModelForMaskedLM.from_pretrained(model_name_or_path)\n        self.model.to(self.device)\n        self.tokenizer = AutoTokenizer.from_pretrained(tokenizer_name or model_name_or_path)\n        self.reverse_voc = {v: k for k, v in self.tokenizer.vocab.items()}\n        self.weight_range = 5\n        self.quant_range = 256\n\n    def encode(self, text, max_length=256, **kwargs):\n        inputs = self.tokenizer([text], max_length=max_length, padding='longest',\n                                truncation=True, add_special_tokens=True,\n                                return_tensors='pt').to(self.device)\n        input_ids = inputs['input_ids']\n        input_attention = inputs['attention_mask']\n        batch_logits = self.model(input_ids)['logits']\n        batch_aggregated_logits, _ = torch.max(torch.log(1 + torch.relu(batch_logits))\n                                               * input_attention.unsqueeze(-1), dim=1)\n        batch_aggregated_logits = batch_aggregated_logits.cpu().detach().numpy()\n        raw_weights = self._output_to_weight_dicts(batch_token_ids, batch_weights)\n        return self._get_encoded_query_token_wight_dicts(raw_weights)[0]\n\n    def _output_to_weight_dicts(self, batch_aggregated_logits):\n        to_return = []\n        for aggregated_logits in batch_aggregated_logits:\n            col = np.nonzero(aggregated_logits)[0]\n            weights = aggregated_logits[col]\n            d = {self.reverse_voc[k]: float(v) for k, v in zip(list(col), list(weights))}\n            to_return.append(d)\n        return to_return\n\n    def _get_encoded_query_token_wight_dicts(self, tok_weights):\n        to_return = []\n        for _tok_weight in tok_weights:\n            _weights = {}\n            for token, weight in _tok_weight.items():\n                weight_quanted = round(weight / self.weight_range * self.quant_range)\n                _weights[token] = weight_quanted\n            to_return.append(_weights)\n        return to_return\n", "path": "pyserini/encode/_splade.py"}], "after_files": [{"content": "import torch\nfrom transformers import AutoModelForMaskedLM, AutoTokenizer\nimport numpy as np\n\nfrom pyserini.encode import QueryEncoder\n\n\nclass SpladeQueryEncoder(QueryEncoder):\n    def __init__(self, model_name_or_path, tokenizer_name=None, device='cpu'):\n        self.device = device\n        self.model = AutoModelForMaskedLM.from_pretrained(model_name_or_path)\n        self.model.to(self.device)\n        self.tokenizer = AutoTokenizer.from_pretrained(tokenizer_name or model_name_or_path)\n        self.reverse_voc = {v: k for k, v in self.tokenizer.vocab.items()}\n        self.weight_range = 5\n        self.quant_range = 256\n\n    def encode(self, text, max_length=256, **kwargs):\n        inputs = self.tokenizer([text], max_length=max_length, padding='longest',\n                                truncation=True, add_special_tokens=True,\n                                return_tensors='pt').to(self.device)\n        input_ids = inputs['input_ids']\n        input_attention = inputs['attention_mask']\n        batch_logits = self.model(input_ids)['logits']\n        batch_aggregated_logits, _ = torch.max(torch.log(1 + torch.relu(batch_logits))\n                                               * input_attention.unsqueeze(-1), dim=1)\n        batch_aggregated_logits = batch_aggregated_logits.cpu().detach().numpy()\n        raw_weights = self._output_to_weight_dicts(batch_aggregated_logits)\n        return self._get_encoded_query_token_wight_dicts(raw_weights)[0]\n\n    def _output_to_weight_dicts(self, batch_aggregated_logits):\n        to_return = []\n        for aggregated_logits in batch_aggregated_logits:\n            col = np.nonzero(aggregated_logits)[0]\n            weights = aggregated_logits[col]\n            d = {self.reverse_voc[k]: float(v) for k, v in zip(list(col), list(weights))}\n            to_return.append(d)\n        return to_return\n\n    def _get_encoded_query_token_wight_dicts(self, tok_weights):\n        to_return = []\n        for _tok_weight in tok_weights:\n            _weights = {}\n            for token, weight in _tok_weight.items():\n                weight_quanted = round(weight / self.weight_range * self.quant_range)\n                _weights[token] = weight_quanted\n            to_return.append(_weights)\n        return to_return\n", "path": "pyserini/encode/_splade.py"}]}