Comments (4)
Okay, you are comparing two different things. The Huggingface Inference Client returns the following object, which has an attribute of usage
that is of type ChatCompletionOutputUsage.
The ChatCompletionOutputUsage
has three types of token usage:
completion_tokens
: This is the number of tokens required to complete the prompt. In your case, this is always fixed because you are calling the same prompt to complete. Try something else, and it should change.prompt_tokens
: The number of tokens in the prompt.total_tokens
: The sum ofcompletion_tokens
andprompt_tokens
.
So, you are implicitly comparing the total_tokens
through the n_tokens
function with completion_tokens
, which is incorrect. You should compare the total_tokens
attribute to make the correct comparison.
P.S. I double-checked the LangChain code and ensured that ChatHuggingFace
is returning the correct ChatCompletionOutputUsage
without any modification.
from langchain.
Okay, you are comparing two different things. The Huggingface Inference Client returns the following object, which has an attribute of
usage
that is of type ChatCompletionOutputUsage.The
ChatCompletionOutputUsage
has three types of token usage:
completion_tokens
: This is the number of tokens required to complete the prompt. In your case, this is always fixed because you are calling the same prompt to complete. Try something else, and it should change.prompt_tokens
: The number of tokens in the prompt.total_tokens
: The sum ofcompletion_tokens
andprompt_tokens
.So, you are implicitly comparing the
total_tokens
through then_tokens
function withcompletion_tokens
, which is incorrect. You should compare thetotal_tokens
attribute to make the correct comparison.P.S. I double-checked the LangChain code and ensured that
ChatHuggingFace
is returning the correctChatCompletionOutputUsage
without any modification.
I think you are misunderstanding the example code, the n_tokens()
function is called on the output of the chain contents, thus the completion_tokens
== n_tokens(output)
- 1. The -1 one is the special end of sequence token (this is why the output says 101 tokens, not 100). The problem is that the ChatCompletionOutputUsage.output_tokens
should always be less or equal to max_new_tokens
, but this is 100 tokens regardless of the supplied max_new_tokens
.
from langchain.
I'm having the same problem... Did you find a solution?
from langchain.
I'm having the same problem... Did you find a solution?
No I have not, this issue renders the entire Huggingface x Langchain implementation obsolete to me. I have been attempting to work around the issue using an OpenAI compatible web server through either LlamaCpp/Ollama.
from langchain.
Related Issues (20)
- Issue: Document loader for Notion DB doesn't supports KeyError: 'name'
- [Google Generative AI] Structured Output doesn't work with advanced schema
- Langchain RetrievalQAWithSourcesChain throwing ValueError: Missing some input keys: {'context'} HOT 3
- IME Input Handling Issue in LangChain Chat Playground
- IME Input Handling Issue in Chat LangChain HOT 2
- OllamaFunction returns Object of type ModelMetaclass is not JSON serializable following example on documentation
- how to insert id_prefix when upserting using langchain pinecone.from_documents??? or what is the alternative? because id_prefix is very important when we want to delete specific vectors
- how to insert id_prefix when upserting using langchain pinecone.from_documents??? or what is the alternative? because id_prefix is very important when we want to delete specific vectors #24235
- DOC: <Please wri知识库交叉融合,在项目使用中,我有一些公用知识库和私有知识库,我想在回答的时候将私有知识库和公用的知识库结合起来,这怎么实现?后期可以更新吗te a comprehensive title after the 'DOC: ' prefix>
- LangChain AzureOpenAIEmbeddings is not working due to model trying to access microsoft HOT 1
- No module named 'langchain.transformers' HOT 3
- issue using tools with ollama local models
- variable chat_history should be a list of base messages, got HOT 2
- Missing key error - Using PromptTemplate and GraphCypherQAChain. HOT 8
- AzureSearch vector store does not support access token authentication. FIX Suggested HOT 2
- TavilySearch parameters don't change the output. HOT 6
- An output parsing error occurred.
- raise ValueError( ValueError: OpenAIChat currently only supports single prompt, got
- ConnectError: [Errno -3] Temporary failure in name resolution HOT 1
- cannot import name 'cast' from 'typing_extensions' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from langchain.