Fix AttributeError in RAG generate() for missing config fields#46035
Merged
Rocketknight1 merged 1 commit intoMay 18, 2026
Conversation
RagSequenceForGeneration.generate() crashes with AttributeError because it accesses self.config.num_return_sequences and self.config.num_beams, but RagConfig never defines these fields. Use getattr with a default of 1 (matching the documented defaults) instead of direct attribute access. Also removes stale references to examples/rag/use_own_knowledge_dataset.py which no longer exists in the repo. Fixes huggingface#46015
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: rag |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
Hi, thank you for take look to one part of #46015 and fix 1 of possibly bunch of issues this could have. The issue of not defined attributes is gone due to default usage of 1 in this case but this not fixes main points as reference to an up to date example instead of removing reference pointed in. We are supposed to be in this state unless i am missing something as the new label on main issue seems to be (Good First Issue), i don't know what does it means but could be related to fix 1 of 3 things maybe ?
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #46015.
What this does
RagSequenceForGeneration.generate()crashes withAttributeError: 'RagConfig' object has no attribute 'num_return_sequences'because the config never definednum_beamsornum_return_sequences.Fix (2 lines in
modeling_rag.py): Usesgetattrwith a default of 1 (matching the documented defaults in thegeneratedocstring) instead of direct attribute access.Adding these fields directly to
RagConfigwas not viable — it triggers the generation utils validation error ("You have modified the pretrained model configuration to control generation"), since generation params belong ingeneration_config, not the model config.Also removes two stale references to
examples/rag/use_own_knowledge_dataset.pyinretrieval_rag.pydocstrings, which no longer exists in the repo.Coordination
Tests run
Note:
pytest tests/models/rag/test_modeling_rag.pysegfaults on macOS ARM due tofaiss-cpu— this is a pre-existing environment issue, not related to this change.AI assistance (Claude Code) was used; all changes were reviewed and tested manually.