text-generation-inference en hi dataset:cfilt/iitb-english-hindi region:us
---
tags:
- text-generation-inference
inference: true
extra_gated_prompt: >-
  This model is open access and available to all, with a CreativeML OpenRAIL-M
  license further specifying rights and usage.

  The CreativeML OpenRAIL License specifies: 


  1. You can't use the model to deliberately produce nor share illegal or
  harmful outputs or content 

  2. CompVis claims no rights on the outputs you generate, you are free to use
  them and are accountable for their use which must not go against the
  provisions set in the license

  3. You may re-distribute the weights and use the model commercially and/or as
  a service. If you do, please be aware you have to include the same use
  restrictions as the ones in the license and share a copy of the CreativeML
  OpenRAIL-M to all your users (please read the license entirely and carefully)

  Please read the full license carefully here:
  https://huggingface.co/spaces/CompVis/stable-diffusion-license
      
extra_gated_heading: Please read the LICENSE to access this model
metrics:
- accuracy
datasets:
- cfilt/iitb-english-hindi
language:
- en
- hi
---

```py
from peft import PeftModel, PeftConfig
from transformers import AutoModelForCausalLM

config = PeftConfig.from_pretrained("ameerazam08/Mistral-7B-v0.1-Eng-Hin")
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-v0.1")
model = PeftModel.from_pretrained(model, "ameerazam08/Mistral-7B-v0.1-Eng-Hin")
```

2. Follow More ABout Mistral [here](https://mistral.ai/news/announcing-mistral-7b/).

# Result-inference-code

```py
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
import warnings
import glob

warnings.filterwarnings("ignore")

base_model_id = "mistralai/Mistral-7B-v0.1"
bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_use_double_quant=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16
)

base_model = AutoModelForCausalLM.from_pretrained(
    base_model_id,
    quantization_config=bnb_config,
    device_map="auto",
    trust_remote_code=True,
    use_auth_token=True
)

tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True, padding_side='left')  # <-- CHANGE MADE HERE
tokenizer.pad_token = tokenizer.eos_token

from peft import PeftModel
ft_model = PeftModel.from_pretrained(base_model, "Peft_model-Path-or-Local-path")
prefix = "translate English to Hindi: "
eval_prompt = prefix+"Translate in Hindi: I am good "
model_input = tokenizer(eval_prompt, return_tensors="pt").to("cuda")

ft_model.eval()
with torch.no_grad():
    print(tokenizer.decode(ft_model.generate(**model_input, max_new_tokens=40, pad_token_id=2, repetition_penalty=1.3)[0], skip_special_tokens=True))

```