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

context len 同时控制了 tokenize之前的string 的len 和 tokenize之后的token len #30

Open
rjagge opened this issue May 10, 2024 · 3 comments

Comments

@rjagge
Copy link

rjagge commented May 10, 2024

如标题所说, context_len参数同时控制了stream_generate_answer函数中token的len:

@torch.inference_mode()
def stream_generate_answer(
        self,
        max_new_tokens=512,
        temperature=0.7,
        repetition_penalty=1.0,
        context_len=8192
):
    streamer = TextIteratorStreamer(self.tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
    input_ids = self._get_chat_input()
    max_src_len = context_len - max_new_tokens - 8

和predict_stream中的str的len:

def predict_stream(
        self,
        query: str,
        max_length: int = 512,
        context_len: int = 8192,
        temperature: float = 0.7,
):
    """Generate predictions stream."""
    stop_str = self.tokenizer.eos_token if self.tokenizer.eos_token else "</s>"
    if not self.enable_history:
        self.history = []
    if self.sim_model.corpus:
        reference_results = self.get_reference_results(query)
        if not reference_results:
            yield '没有提供足够的相关信息', reference_results
        reference_results = self._add_source_numbers(reference_results)
        context_str = '\n'.join(reference_results)[:(context_len - len(PROMPT_TEMPLATE))]
        prompt = PROMPT_TEMPLATE.format(context_str=context_str, query_str=query)
        logger.debug(f"prompt: {prompt}")

这样会导致, prompt注入的知识永远和模型的最大上下文能力不匹配.

如果可以我可以提个pull request.

@shibing624
Copy link
Owner

提吧。

@cristianohello
Copy link

@rjagge
nice!

@rjagge
Copy link
Author

rjagge commented May 21, 2024

@shibing624 提了

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

No branches or pull requests

3 participants