Skip to content

Conversation

rkazants
Copy link
Collaborator

@rkazants rkazants commented Jun 20, 2025

What does this PR do?

Support Zyphra/Zamba2-1.2B-Instruct-v2

from transformers import AutoTokenizer
from optimum.intel.openvino import OVModelForCausalLM

# Load tokenizer and OpenVINO model
model_dir = "Zyphra/Zamba2-1.2B-Instruct-v2"
tokenizer = AutoTokenizer.from_pretrained(model_dir)
model = OVModelForCausalLM.from_pretrained(model_dir)

# Prepare input
prompt = "What is the capital of France?"
inputs = tokenizer(prompt, return_tensors="pt")

# Run inference
output_ids = model.generate(**inputs, max_new_tokens=50)
output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)

print(output_text)

Before submitting

  • [N/A] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@echarlaix echarlaix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the addition @rkazants

rkazants added 2 commits July 31, 2025 21:59
Signed-off-by: Kazantsev, Roman <[email protected]>
Signed-off-by: Kazantsev, Roman <[email protected]>
Copy link
Collaborator

@echarlaix echarlaix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for iterating @rkazants, looks like the tests are not passing would you mind taking a look ?

past_key_values = []
# generate tuples of (key, value, conv_state, ssm_state)
for i in range(self.num_hidden_layers):
kv_shape = (self.batch_size, self.num_attention_heads, 1, self.head_dim)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here why not

Suggested change
kv_shape = (self.batch_size, self.num_attention_heads, 1, self.head_dim)
kv_shape = (self.batch_size, self.num_attention_heads, self.sequence_length, self.head_dim)

value_cache = []
# inputs passed in an order of (key, value, conv_state, ssm_state)
for idx in range(num_hidden_layers):
batch_size = past_key_values[4 * idx].size(0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not very important but could be moved outside from loop

attention_mask=attention_mask,
position_ids=position_ids,
past_key_values=wrapped_cache_params,
# cache_position=cache_position,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ?

ssm_states = []
key_cache = []
value_cache = []
# inputs passed in an order of (key, value, conv_state, ssm_state)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok so length of past_key_values is always 4 * num_hidden_layers is this correct ? if yes would you mind adding ?

@IlyasMoutawwakil
Copy link
Member

@rkazants can you please rebase your branch, run styling and make sure the tests are passing 🙏

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

Successfully merging this pull request may close these issues.

4 participants