Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v0.2.3.beta.1] RAG #206

Merged
merged 23 commits into from
Sep 17, 2024
Merged

[v0.2.3.beta.1] RAG #206

merged 23 commits into from
Sep 17, 2024

Conversation

liyin2015
Copy link
Collaborator

@liyin2015 liyin2015 commented Sep 11, 2024

  • Designing RAG
  • Benchmark RAG
  • Optimize RAG

(make any task pipeline auto-differentiable), generator used in retriever (rewrite, retrieve, read), retrieve + read (train these two RAGs on hotpot qa datasets)

need to improve the clarity on GradComponent, tensor + parameter (potentially differentiate trainable parameters with other intermediates outputs/inputs in the pipeline)

  • Defined clear parameter type
  • defined a forward func which is a wrapper on call function to handle parameter and dynamic computation graph
  • Adapted default gradcomponnet's forward
  • customized retriever's forward to save top_k as hyperparam and input as input type

Here is the computation graph using the following code for a vanila rag pipeline

    def foward(self, question: str, id: str = None) -> adal.Parameter:
        retriever_out = self.retriever.forward(input=question)
        successor_map_fn = lambda x: (
            "\n\n".join(x.data[0].documents)
            if x.data and x.data[0] and x.data[0].documents
            else ""
        )
        retriever_out.add_successor_map_fn(successor=self.llm, map_fn=successor_map_fn)
        generator_out = self.llm.forward(
            prompt_kwargs={"question": question, "context": retriever_out}, id=id
        )
        return generator_out

The computation graph

trace_graph_Generator_output

TODO:

  • backward tests on classification + qa use case, potentially simplify previous code.
  • tutorial + notebook for rag optimization

@liyin2015 liyin2015 changed the title [wip] RAG [v0.2.3.beta.1] RAG Sep 17, 2024
@Sylph-AI Sylph-AI merged commit 030c128 into main Sep 17, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants