pranjalchitale VarunGumma commited on
Commit
34281d4
·
verified ·
1 Parent(s): 1ec8585

Update README.md (#2)

Browse files

- Update README.md (1a225950ddfd74cea6e10bd23e6dcdfac2946a9b)


Co-authored-by: Varun Gumma <VarunGumma@users.noreply.huggingface.co>

Files changed (1) hide show
  1. README.md +15 -11
README.md CHANGED
@@ -61,17 +61,22 @@ Please refer to the [github repository](https://github.com/AI4Bharat/IndicTrans2
61
 
62
  ```python
63
  import torch
64
- from transformers import (
65
- AutoModelForSeq2SeqLM,
66
- AutoTokenizer,
67
- )
68
  from IndicTransToolkit import IndicProcessor
 
 
 
69
 
70
-
71
  model_name = "ai4bharat/indictrans2-indic-en-dist-200M"
72
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
73
 
74
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name, trust_remote_code=True)
 
 
 
 
 
75
 
76
  ip = IndicProcessor(inference=True)
77
 
@@ -82,8 +87,6 @@ input_sentences = [
82
  "मेरे मित्र ने मुझे उसके जन्मदिन की पार्टी में बुलाया है, और मैं उसे एक तोहफा दूंगा।",
83
  ]
84
 
85
- src_lang, tgt_lang = "hin_Deva", "eng_Latn"
86
-
87
  batch = ip.preprocess_batch(
88
  input_sentences,
89
  src_lang=src_lang,
@@ -128,9 +131,10 @@ for input_sentence, translation in zip(input_sentences, translations):
128
  print(f"{tgt_lang}: {translation}")
129
  ```
130
 
131
- **Note: IndicTrans2 is now compatible with AutoTokenizer, however you need to use IndicProcessor from [IndicTransTokenizer](https://github.com/VarunGumma/IndicTransTokenizer) for preprocessing before tokenization.**
132
-
133
-
 
134
 
135
  ### Citation
136
 
 
61
 
62
  ```python
63
  import torch
64
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
 
 
 
65
  from IndicTransToolkit import IndicProcessor
66
+ # recommended to run this on a gpu with flash_attn installed
67
+ # don't set attn_implemetation if you don't have flash_attn
68
+ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
69
 
70
+ src_lang, tgt_lang = "hin_Deva", "eng_Latn"
71
  model_name = "ai4bharat/indictrans2-indic-en-dist-200M"
72
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
73
 
74
+ model = AutoModelForSeq2SeqLM.from_pretrained(
75
+ model_name,
76
+ trust_remote_code=True,
77
+ torch_dtype=torch.float16, # performance might slightly vary for bfloat16
78
+ attn_implementation="flash_attention_2"
79
+ ).to(DEVICE)
80
 
81
  ip = IndicProcessor(inference=True)
82
 
 
87
  "मेरे मित्र ने मुझे उसके जन्मदिन की पार्टी में बुलाया है, और मैं उसे एक तोहफा दूंगा।",
88
  ]
89
 
 
 
90
  batch = ip.preprocess_batch(
91
  input_sentences,
92
  src_lang=src_lang,
 
131
  print(f"{tgt_lang}: {translation}")
132
  ```
133
 
134
+ ### 📢 Long Context IT2 Models
135
+ - New RoPE based IndicTrans2 models which are capable of handling sequence lengths **upto 2048 tokens** are available [here](https://huggingface.co/collections/prajdabre/indictrans2-rope-6742ddac669a05db0804db35)
136
+ - These models can be used by just changing the `model_name` parameter. Please read the model card of the RoPE-IT2 models for more information about the generation.
137
+ - It is recommended to run these models with `flash_attention_2` for efficient generation.
138
 
139
  ### Citation
140