MODEL_TO_ENCODING mapping does not work with Azure naming restrictions
Azure does not allow for . in the model name. tiktoken package is used by other packages e.g., langchain. Patching this naming restrictions in tiktoken seems like the best fix.
Problem:
GPT-3.5-turbo cannot be a valid name in model deployed in Azure
PR #72 may fix this.
Thanks for bringing this up!
I'm actually not too familiar with the Azure SKUs. Do you have a link to them handy? That way I could attempt to make sure they're covered in the model to encoding mapping in the future.
Basically langchain package uses tiktoken with encoding_for_model() method. So it expects to find a match in the model.py mapping. When deploying a OpenAI model via Azure, one can choose the model name (i.e., in order to match the standard OpenAI model names). However, these model names cannot include any dots in the name. Hence it is not possible to match the gpt-3.5-turbo name. The root cause of this is of course on the Azure side (or one could argue that langchain has the same issue), but I would assume that extending the mapping in tiktoken is the easiest fix for this.
@hauntsaninja Thank you for helping the community with maintaining this package.
Currently, when working with popular frameworks in conjunction with models deployed on Azure OpenAI Platform, we get an error message as follows.
KeyError: ‘Could not automatically map "<custom-prefix>-text-embedding-ada-002-<custom-suffix>" to a tokeniser. Please use `tiktok.get_encoding` to explicitly get the tokeniser you expect.'
This is due to the hardcoded dictionary for model name and encoding pairs (MODEL_TO_ENCODING)
Do you think we have an alternative here?
If not, in larger enterprises where you would need to add tag and/or prefix/suffix Model Deployments for accounting purposes, having restrictions on naming may not always be a great idea. As I understand it, this is done so that we validate the pairing of the encoder and model variants. The model names on Azure OpenAI Platform can almost be anything that the customer chooses.
Especially considering most frameworks including OpenAI package use tiktoken package, it may be easier to allow flexibility in this module rather than each of us forking a new repository for this tokeniser package.
Given that you have great documentation around model variants and tokenizers used, may I please suggest making these <model name, encoding> pair configurable with sensible defaults?
Thanks much!
Just hit this same issue, had to manually patch models.py to allow the use of tiktoken for gpt-35-turbo.
@hauntsaninja Thank you for helping the community with maintaining this package.
Currently, when working with popular frameworks in conjunction with models deployed on Azure OpenAI Platform, we get an error message as follows.
KeyError: ‘Could not automatically map "<custom-prefix>-text-embedding-ada-002-<custom-suffix>" to a tokeniser. Please use `tiktok.get_encoding` to explicitly get the tokeniser you expect.'This is due to the hardcoded dictionary for model name and encoding pairs (MODEL_TO_ENCODING)
Do you think we have an alternative here?
If not, in larger enterprises where you would need to add tag and/or prefix/suffix Model Deployments for accounting purposes, having restrictions on naming may not always be a great idea. As I understand it, this is done so that we validate the pairing of the encoder and model variants. The model names on Azure OpenAI Platform can almost be anything that the customer chooses.
Especially considering most frameworks including OpenAI package use
tiktokenpackage, it may be easier to allow flexibility in this module rather than each of us forking a new repository for this tokeniser package.Given that you have great documentation around model variants and tokenizers used, may I please suggest making these
<model name, encoding>pair configurable with sensible defaults?Thanks much!
Hi @jerrygb , I don't think model names on Azure OpenAI Platform can almost be anything that the customer chooses. because we only can do is change/create a Deployment model name. Model name is not equal to Deployment name. we can not change deployment name than fix this issue. because there is model name not matching between "gpt-3.5-turbo" and "gpt-35-turbo"
@jerrygb sorry, you are right. I have confirm that we can change code to below, then will fix this issue:
change "gpt-35-turbo" to "gpt-3.5-turbo" when you init AzureOpenAI
this issue seems like is a LangChain issue that they not matching "gpt-35-turbo" when using AzureOpenAI
This looks like its fixed with https://github.com/openai/tiktoken/commit/affbd6e50da3f15ea044ea10d71e63d2429b66d4 but not released yet. Do we know when the next release will be?
Thanks all, this was released in 0.5.0