CarperAI / trlx

A repo for distributed training of language models with Reinforcement Learning via Human Feedback (RLHF)
MIT License
4.51k stars 471 forks source link

Data Loader Bug when running t5_summarization_daily_cnn.py #595

Open yunanyan opened 5 months ago

yunanyan commented 5 months ago

🐛 Describe the bug

I got this error when running the t5_summarization_daily_cnn.py

Traceback (most recent call last): File "/home/mydata/trlx/examples/summarize_daily_cnn/t5_summarize_daily_cnn.py", line 112, in trlx.train( File "/home/mydata/trlx/trlx/trlx.py", line 142, in train trainer.learn() File "/home/mydata/trlx/trlx/trainer/accelerate_base_trainer.py", line 524, in learn self.prepare_learning() File "/home/mydata/trlx/trlx/trainer/accelerate_ppo_trainer.py", line 237, in prepare_learning self.make_experience(self.config.method.num_rollouts) File "/home/mydata/trlx/trlx/trainer/accelerate_ppo_trainer.py", line 280, in make_experience batch: PromptBatch = next(self.prompt_iterator) File "/home/mydata/trlx/trlx/utils/init.py", line 250, in infinite_dataloader yield from dataloader File "/opt/conda/lib/python3.10/site-packages/accelerate/data_loader.py", line 463, in iter current_batch = send_to_device(current_batch, self.device, non_blocking=self._non_blocking) File "/opt/conda/lib/python3.10/site-packages/accelerate/utils/operations.py", line 159, in send_to_device return tensor.to(device) File "/opt/conda/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 800, in to self.data = {k: v.to(device=device) for k, v in self.data.items()} File "/opt/conda/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 800, in self.data = {k: v.to(device=device) for k, v in self.data.items()} AttributeError: 'list' object has no attribute 'to'

When I look into the problem, it is caused by the data loader. When the batch tensors are passed, only the prompt and mask are properly encoded as tensors. The 'original summary' is still a list of text. I print out the 'tensor' for your reference:

'input_ids': tensor([[12198, 1635, 1737, ..., 79, 33, 1], [12198, 1635, 1737, ..., 7801, 21, 1], [12198, 1635, 1737, ..., 11819, 7, 1], ..., [12198, 1635, 1737, ..., 8, 3, 1], [12198, 1635, 1737, ..., 2817, 16, 1], [ 0, 0, 0, ..., 13143, 5, 1]]), 'attention_mask': tensor([[1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1], ..., [1, 1, 1, ..., 1, 1, 1], [1, 1, 1, ..., 1, 1, 1], [0, 0, 0, ..., 1, 1, 1]]), 'original_summaries': ['Humans began domesticating cattle, Bos taurus, about 8,500 years ago .\nAmericans today consume nearly 63 pounds of beef per person each year .\nMost of us tend to stick with beef cuts we know .', "Tajikistan, Uzbekistan may allow U.S. military supplies heading to Afhanistan .\nKyrgyzstan president completes next step towards closure of U.S. base .\nThe U.S. says it's still working with the country to keep the operation open .\nThe Manas base is used to transport key supplies and troops into Afghanistan .", 'Suspected U.S. CIA agents ordered jailed for seizing of suspected terrorist in Milan .\nAmericans are not in custody, but ruling could make them international fugitives .\nCase centered on "extraordinary rendition" of Muslim cleric, who says he was tortured in Egypt .', 'NEW: Father: "My family is still gone"\nThe penalty phase is scheduled to begin October 18 .\nSteven Hayes is convicted of capital murder .\nJurors acquitted Hayes of an arson charge .', 'Research In Motion may unveil a tablet device at its conference next week, a report says .\nThe device is sometimes called a "BlackPad" since RIM bought the domain blackpad.com .\nWall Street reports that tablet will use a new OS from QNX Software .', 'Athletes met age requirements, international commission concludes .\nSome writers, others suspected girls were younger than rules allowed .\nChinese team won gold medal in Summer Olympics at Beijing .\nPassports, identity cards, household records examined .', 'Felipe Massa suffers high-speed crash in qualifying for Hungarian Grand Prix .\nMassa was hit in the helmet by debris from the Brawn GP of Rubens Barrichello .\nBrazilian has emergency surgery after damaging his skull in the accident .\nFernando Alonso took pole when final qualifying resumes at the Hungaroring .', 'NEW: A Palestinian official calls for sincere steps from Israel .\nPresident Obama says the idea of pre-1967 borders with land swaps is nothing new .\nAny controversy over his speech on the issue lacks substance, Obama says .\nThe president spoke to the main American-Israel lobbying group .', 'Sources told PEOPLE that Gisele Bundchen and Tom Brady have had a baby boy .\nThe couple got married February in a private ceremony in Los Angeles .\nThe child is the first for the Brazilian model; the second for Brady .', 'Russia argues that France violated a U.N. Security Council resolution, a diplomat says .\nDiplomat: Drops were "the only practical way of fulfilling" the council\'s mandate .\nUnited States, United Kingdom defend France, the diplomat says .\nFrance\'s defense minister says the weapons drops are no longer necessary .', 'NEW: Armed robbery failed in upscale New York clothing store .\nNEW: Alleged robber fled south, robbing two hotels in Maryland .\nNEW: Suspected drunken driver turned out to be NYC robbery suspect .\nNEW: Fatal chase lasted 2 1/2 miles, reaching speeds of 120 mph .', "Britain's oldest man, oldest veteran from World War I, celebrates his 112th birthday .\nHenry Allingham last founding member of the Royal Air Force, formed in 1918 .\nEx-aircraft engineer still travels, makes public appearances at military events ."]}

Obviously the original summary is not properly tokenized. Please let me know if this bug can be replicated and fixed. Thanks!

Which trlX version are you using?

trlx = 0.7.0 newest version

Additional system and package information

transformers 4.41.2