Qwen/Qwen-7B-Chat
An error occurred (ModelError) when calling the InvokeEndpoint operation: Received client error (400) from primary with message "{“code”: 400,“type”: “InternalServerException”,“message”: “Tokenizer class Qwen2Tokenizer does not exist or is not currently imported.”}getting these error:the custom inference.py%%writefile code/inference.pyfrom transformers import AutoTokenizer, AutoModelimport torchimport torch.nn.functional as FHelper: Mean Pooling - Take attention mask into account for correct averagingdef mean_pooling(model_output, attention_mask):token_embeddings = model_output[0]#Firstelement of model_output contains all token embeddingsinput_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)def model_fn(model_dir):Load model from HuggingFace Hubtokenizer = AutoTokenizer.from_pretrained(model_dir)model = AutoModel.from_pretrained(model_dir)return model, tokenizerdef predict_fn(data, model_and_tokenizer):# destruct model and tokenizermodel, tokenizer = model_and_tokenizer# Tokenize sentences
sentences = data.pop("inputs", data)
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt', trust_remote_code=True)

# Compute token embeddings
with torch.no_grad():
    model_output = model(**encoded_input)

# Perform pooling
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])

# Normalize embeddings
sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)

# return dictonary, which will be json serializable
return {"vectors": sentence_embeddings[0].tolist()}predict_fn.accepts_trust_remote_code = True