-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Getting Assertion Error when calling neo4j chain for inference #29100
Comments
Hi @KaifAhmad1, thanks for opening an issue! Please make sure to provide a minimal code reproducer and information about the bug encountered, including the full error traceback when reporting an issue. If the error is coming from |
Hey, @amyeroberts bitsandbytes = 0.42.0 import torch
from torch import cuda, bfloat16
import transformers
model_id = 'microsoft/phi-2'
device = f'cuda:{cuda.current_device()}' if cuda.is_available() else 'cpu'
# begin initializing HF items, you need an access token
model_config = transformers.AutoConfig.from_pretrained(
model_id,
use_auth_token=hf_auth,
trust_remote_code=True
)
# BnB Configuration
bnb_config = transformers.BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type='nf4',
bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype=bfloat16
)
model = transformers.AutoModelForCausalLM.from_pretrained(
model_id,
trust_remote_code=True,
config=model_config,
device_map='auto',
use_auth_token=hf_auth,
quantization_config=bnb_config,
low_cpu_mem_usage=True
)
# How model looks like:
model.eval()
from langchain.chains import GraphCypherQAChain
from langchain.graphs import Neo4jGraph
from langchain.chains.base import Chain
from langchain.chains.llm import LLMChain
from langchain.chat_models import ChatOpenAI
from langchain.chains.question_answering.stuff_prompt import CHAT_PROMPT
from langchain.callbacks.manager import CallbackManagerForChainRun
from typing import Any, Dict, List
from pydantic import Field
vector_search = """
WITH
k, e) yield node, score
RETURN node.text AS result
ORDER BY score DESC
LIMIT 3
"""
print(graph.schema)
class Neo4jVectorChain(Chain):
graph: Neo4jGraph = Field(exclude=True)
input_key: str = "query"
output_key: str = "result"
embeddings: HuggingFaceBgeEmbeddings = HuggingFaceBgeEmbeddings()
qa_chain: LLMChain = LLMChain(llm=llm, prompt=CHAT_PROMPT)
@property
def input_keys(self) -> List[str]:
return [self.input_key]
@property
def output_keys(self) -> List[str]:
_output_keys = [self.output_key]
return _output_keys
def _call(self, inputs: Dict[str, str], run_manager, k=3) -> Dict[str, Any]:
question = inputs[self.input_key]
embedding = self.embeddings.embed_query(question)
context = self.graph.query(vector_search, {'embedding': embedding, 'k': 3})
context = [el['result'] for el in context]
result = self.qa_chain({"question": question, "context": context})
final_result = result[self.qa_chain.output_key]
return {self.output_key: final_result}
chain = Neo4jVectorChain(graph=graph, embeddings=embeddings, verbose=True)
graph_result = chain.run("How can we enhance the specificity and efficiency of CRISPR/Cas9 gene-editing technology to minimize off-target effects and increase its potential for therapeutic applications?")
|
Hi @KaifAhmad1 |
System Info
langchain version = 0.1.7
bitsandbytes = 0.42.0
pip = 24.0
cuda = 12.1
OS Windows 11 x64
Who can help?
Hey, @SunMarc @younesbelkada please help me out.
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
I've brought up this concern on LangChain, but Duso-Bot is indicating that it's actually related to BitsAndBytes.
Here is the discussion link and issue: langchain-ai/langchain#17701
also raised on bitsandbytes repo but did not get support. Link: bitsandbytes-foundation/bitsandbytes#1067
Expected behavior
It wil give the answes without raising the exception. answer
The text was updated successfully, but these errors were encountered: