# Convert pagasus to dynamic quantize for best perfomance

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fconvert-pagasus-to-dynamic-quantize-for-best-perfomance%2F29973%3E%5C
**Category:** Beginners\
**Created:** [January 18, 2023, 9:50pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fconvert-pagasus-to-dynamic-quantize-for-best-perfomance%2F29973 "2023-01-18T21:50:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stormIA](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@stormIA](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FstormIA)%5C
**Post date:** [January 18, 2023, 9:50pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fconvert-pagasus-to-dynamic-quantize-for-best-perfomance%2F29973%2F1 "2023-01-18T21:50:21Z")

</div>

Can you help me to pass this code to Dinamyc Quantize, it is a hugging face model based on Pegasus (google/pegasus-xsum), I have low perfomance and investigating, you can use dynamic quantize in this kind of models. Can someone give me a hand, I am a newbie. ☹  
If you could give me some tips about hyperparameters in the pipeline, it would be very helpful.

```auto
from transformers import pipeline ,PegasusForConditionalGeneration, PegasusTokenizer
from config import Config
import torch
import os
from utils import Utils

torch.manual_seed(42)
torch.set_grad_enabled(False)

num_threads, device = Utils.get_device_threads()
torch.set_num_threads(num_threads)
    
class Summarize:
  def __init__ (self):
      
      self.model_name = Config['MODEL_NAME']
      self.tokenizer = PegasusTokenizer.from_pretrained(Config['MODEL_NAME'])
      self.model = PegasusForConditionalGeneration.from_pretrained(Config['MODEL_NAME']).eval()
      self.summarizer = pipeline("summarization", model=self.model_name, tokenizer=self.tokenizer, framework="pt",batch_size=2,device= device)
  
  def summarize(self, conversation, max_token):
    try:
      gen_kwargs = {"max_length": max_token, "length_penalty":0.1, "num_beams": 1, "early_stopping": True, "min_length": 10, "max_length": 512, "temperature":0.5,"no_repeat_ngram_size": 3}
      return self.summarizer(conversation, **gen_kwargs)[0]['summary_text']
    except:
      return "Sorry, I was unable to generate a summary for this conversation"

```
