Vipitis commited on
Commit
a0059eb
1 Parent(s): 9361469

implemnting a fix for santacoder

Browse files
Files changed (1) hide show
  1. ShaderEval.py +6 -3
ShaderEval.py CHANGED
@@ -28,7 +28,7 @@ from evaluate.evaluation_suite import SubTask
28
  from datasets import Dataset
29
  from typing import Any, Callable, Dict, List, Optional, Union # used in .prepare_pipeline()
30
  import transformers
31
- from transformers import Pipeline, pipeline, GenerationConfig #GenerationConfig to specify greedy and avoid error
32
  from datasets import load_dataset #used by Suite.run()
33
 
34
  # write a custom evaluator, inherent from: https://github.com/huggingface/evaluate/blob/v0.4.0/src/evaluate/evaluator/text_generation.py#L31
@@ -76,6 +76,9 @@ class ReturnGenerationEvaluator(evaluate.TextGenerationEvaluator):
76
  or isinstance(model_or_pipeline, transformers.PreTrainedModel)
77
  or isinstance(model_or_pipeline, transformers.TFPreTrainedModel)
78
  ):
 
 
 
79
  pipe = pipeline(
80
  self.task,
81
  model=model_or_pipeline,
@@ -126,7 +129,7 @@ class ReturnGenerationEvaluator(evaluate.TextGenerationEvaluator):
126
  if isinstance(model_or_pipeline, transformers.GPT2Model): # you are comparing a string here -.-
127
  return model_or_pipeline.config.n_ctx # how GPT2 models might handle is, seen with
128
  if pipe is not None: #should I figure out a way to pass this.
129
- pipe.tokenizer.model_max_length # this is set to something small for pipeline default task, but we would want to put it to the max instead.
130
  # tokenizer needs to know the context length for our pipe strategy, but it has to be passed to the tokenizer, not model.
131
  # the tokenizer should read from the model config, but that can be wrong, or it has a task overwrite (for "text-generation" for example you get 50)
132
  #model_or_pipeline only exists via the .compute call, so we have to take it in
@@ -143,7 +146,7 @@ class ReturnGenerationEvaluator(evaluate.TextGenerationEvaluator):
143
  `int`: the estimated max_new_tokens, should be smaller than context_lenght in all cases
144
  """
145
  context_lenght = self._resolve_context_lenght(**kwargs)
146
- estimate = min(max([len(ref) for ref in labels]) + 5, context_lenght)
147
  return estimate
148
 
149
  # this one needs to be adjusted
 
28
  from datasets import Dataset
29
  from typing import Any, Callable, Dict, List, Optional, Union # used in .prepare_pipeline()
30
  import transformers
31
+ from transformers import Pipeline, pipeline, GenerationConfig, AutoTokenizer #GenerationConfig to specify greedy and avoid error
32
  from datasets import load_dataset #used by Suite.run()
33
 
34
  # write a custom evaluator, inherent from: https://github.com/huggingface/evaluate/blob/v0.4.0/src/evaluate/evaluator/text_generation.py#L31
 
76
  or isinstance(model_or_pipeline, transformers.PreTrainedModel)
77
  or isinstance(model_or_pipeline, transformers.TFPreTrainedModel)
78
  ):
79
+ # load tokenizer manually, since the pipeline does fail to do so at times. needed for bigcode/santacoder for example.
80
+ tokenizer = AutoTokenizer.from_pretrained(model_or_pipeline)
81
+
82
  pipe = pipeline(
83
  self.task,
84
  model=model_or_pipeline,
 
129
  if isinstance(model_or_pipeline, transformers.GPT2Model): # you are comparing a string here -.-
130
  return model_or_pipeline.config.n_ctx # how GPT2 models might handle is, seen with
131
  if pipe is not None: #should I figure out a way to pass this.
132
+ return pipe.tokenizer.model_max_length # this is set to something small for pipeline default task, but we would want to put it to the max instead.
133
  # tokenizer needs to know the context length for our pipe strategy, but it has to be passed to the tokenizer, not model.
134
  # the tokenizer should read from the model config, but that can be wrong, or it has a task overwrite (for "text-generation" for example you get 50)
135
  #model_or_pipeline only exists via the .compute call, so we have to take it in
 
146
  `int`: the estimated max_new_tokens, should be smaller than context_lenght in all cases
147
  """
148
  context_lenght = self._resolve_context_lenght(**kwargs)
149
+ estimate = min(max([len(ref) for ref in labels]) + 5, context_lenght) #does the min call get done inside the pipeline anyway? is there even a single case where the return statement is this long?
150
  return estimate
151
 
152
  # this one needs to be adjusted