zurichnlp / mbr Goto Github PK
View Code? Open in Web Editor NEWMinimum Bayes Risk Decoding for Hugging Face Transformers
License: Apache License 2.0
Minimum Bayes Risk Decoding for Hugging Face Transformers
License: Apache License 2.0
The decoding code is currently not compatible with versions of Hugging Face transformers >= v4.39:
======================================================================
ERROR: test_generate (test_generate.DecoderOnlyTestCase.test_generate)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/work/mbr/mbr/tests/test_generate.py", line 28, in test_generate
output = self.model.generate(
^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/mbr/generation/utils.py", line 344, in generate
generation_mode = self._get_generation_mode(generation_config, assistant_model)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1709, in __getattr__
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
AttributeError: 'MBRGPT2LMHeadModel' object has no attribute '_get_generation_mode'
Currently running into an issue that arises whenever the num_return_sequences > 1. Otherwise the code works when num_return_sequences=1:
mbr_bart = MBR(BartForConditionalGeneration).from_pretrained("mymodel")
mbr_config = MBRConfig(
num_samples=5,
)
inps = bart_tokenizer(src, return_tensors='pt').to('cuda')
mbr_bart.generate(**inps, do_sample=True, mbr_config=mbr_config, tokenizer=bart_tokenizer, num_beams=1, num_return_sequences=2, max_new_tokens=25, epsilon_cutoff=0.02)
-----------------------------------------------------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In[66], line 24
18 mbr_config = MBRConfig(
19 num_samples=5,
20 )
23 inps = bart_tokenizer(src, return_tensors='pt').to('cuda')
---> 24 mbr_bart.generate(**inps, do_sample=True, mbr_config=mbr_config, tokenizer=bart_tokenizer, num_beams=1, num_return_sequences=2, max_new_tokens=25, epsilon_cutoff=0.02)
File ~/.local/lib/python3.9/site-packages/torch/utils/_contextlib.py:115, in context_decorator.<locals>.decorate_context(*args, **kwargs)
112 @functools.wraps(func)
113 def decorate_context(*args, **kwargs):
114 with ctx_factory():
--> 115 return func(*args, **kwargs)
File ~/.local/lib/python3.9/site-packages/mbr/generation/utils.py:506, in MBRGenerationMixin.generate(self, inputs, generation_config, references_config, mbr_config, tokenizer, metric_runner, logits_processor, stopping_criteria, prefix_allowed_tokens_fn, synced_gpus, assistant_model, streamer, negative_prompt_ids, negative_prompt_attention_mask, progress_bar, **kwargs)
498 output = MBROutput(
499 sequences=generation_config.pad_token_id * torch.ones((batch_size, max_length), dtype=torch.long),
500 all_samples=(tuple(samples) if mbr_config.output_all_samples else None),
(...)
503 metric_scores=(metric_output if mbr_config.output_metric_scores else None),
504 )
505 for batch_idx, sample_idx in enumerate(top_metric_indices):
--> 506 output.sequences[batch_idx][:sample_ids[sample_idx].shape[1]] = sample_ids[sample_idx][batch_idx]
508 if mbr_config.return_dict_in_generate:
509 return output
IndexError: index 1 is out of bounds for dimension 0 with size 1
Thank you for your time!
Hi facing the following issue while reproducing run_experiment.py in bertsch et al:
raise TypeError(f"mbr_config.metric_kwargs must be hashable.") from e
TypeError: mbr_config.metric_kwargs must be hashable.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.