Skip to content

Commit 5bc5e91

Browse files
committed
update readme instructions
1 parent 20839e8 commit 5bc5e91

File tree

16 files changed

+238
-5
lines changed

16 files changed

+238
-5
lines changed

README.md

Lines changed: 236 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,243 @@ hints to the student to arrive at correct answer, enhancing student engagement a
6060

6161
![](./assets/Tech-Stack.png)
6262

63-
List Down all technologies used to Build the prototype **Clearly mentioning Intel® AI Analytics Toolkits, it's libraries and the SYCL/DCP++ Libraries used**
64-
6563
## Step-by-Step Code Execution Instructions:
66-
Stay Tuned!
64+
65+
a) Easy Option to Start Demo
66+
67+
- Clone the Repository
68+
```console
69+
$ git clone https://github.com/rohitc5/intel-oneAPI/tree/main
70+
$ cd Intel-oneAPI
71+
72+
```
73+
- Start the LEAP RESTFul Service to consume both components (Ask Question/Doubt and Interactive Conversational AI Examiner) over API
74+
75+
```console
76+
$ cd api
77+
78+
# build the docker file
79+
$ docker build -t leap-api:v1 .
80+
81+
# get the docker image ID
82+
$ docker images
83+
84+
# run the docker container
85+
$ docker run -it -p 8500:8500 --name=leap-api [IMAGE_ID]
86+
87+
$ cd ../
88+
89+
```
90+
91+
- Start the demo webapp build using streamlit
92+
93+
```console
94+
$ cd webapp
95+
96+
# build the docker file
97+
$ docker build -t leap-demo:v1 .
98+
99+
# get the docker image ID
100+
$ docker images
101+
102+
# run the docker container
103+
$ docker run -it -p 8502:8502 --name=leap-demo [IMAGE_ID]
104+
105+
```
106+
107+
b) Step-by-Step Option
108+
109+
- Clone the Repository
110+
111+
```console
112+
$ git clone https://github.com/rohitc5/intel-oneAPI/tree/main
113+
$ cd Intel-oneAPI
114+
115+
```
116+
117+
- Train/Fine-tune the Extractive QA Multilingual Model (Part of our Ask Question/Doubt Component).
118+
Please note that, by default we use this (https://huggingface.co/ai4bharat/indic-bert) as a Backbone (BERT topology)
119+
and finetune it on SQuAD v1 dataset. Moreover, IndicBERT is a multilingual ALBERT model pretrained exclusively on 12 major Indian languages. It is pre-trained on novel monolingual corpus of around 9 billion tokens and subsequently evaluated on a set of diverse tasks. So finetuning, on SQuAD v1 (English) dataset automatically results in cross-lingual
120+
transfer on other 11 indian languages.
121+
122+
Here is the detailed architecture of `Ask Question/Doubt` component:
123+
124+
![](./assets/Ask-Doubt.png)
125+
126+
```console
127+
$ cd nlp/question_answering
128+
129+
# install dependencies
130+
$ pip install -r requirements.txt
131+
132+
# modify the fine-tuning params mentioned in finetune_qa.sh
133+
$ vi finetune_qa.sh
134+
135+
''''
136+
export MODEL_NAME_OR_PATH=ai4bharat/indic-bert
137+
export BACKBONE_NAME=indic-mALBERT-base
138+
export DATASET_NAME=squad # squad, squad_v2 (pass --version_2_with_negative)
139+
export TASK_NAME=qa
140+
141+
# hyperparameters
142+
export SEED=42
143+
export BATCH_SIZE=32
144+
export MAX_SEQ_LENGTH=512
145+
export NUM_TRAIN_EPOCHS=5
146+
...
147+
148+
''''
149+
150+
# start the training after modifying params
151+
$ bash finetune_qa.sh
152+
```
153+
154+
- Optimize using IPEX, Intel® Neural Compressor and run the bennchmark for comparison with Pytorch(Base)-FP32
155+
156+
```console
157+
# modify the params in pot_benchmark_qa.sh
158+
$ vi pot_benchmark_qa.sh
159+
160+
''''
161+
export MODEL_NAME_OR_PATH=artifacts/qa/squad/indic-mALBERT
162+
export BACKBONE_NAME=indic-mALBERT
163+
export DATASET_NAME=squad # squad, squad_v2 (pass --version_2_with_negative)
164+
export TASK_NAME=qa
165+
export USE_OPTIMUM=True # whether to use hugging face wrapper optimum around intel neural compressor
166+
167+
# other parameters
168+
export BATCH_SIZE=8
169+
export MAX_SEQ_LENGTH=256
170+
export DOC_STRIDE=128
171+
export KEEP_ACCENTS=False
172+
export DO_LOWER_CASE=True
173+
export MAX_EVAL_SAMPLES=200
174+
175+
export TUNE=True # whether to tune or not
176+
export PTQ_METHOD="static_int8" # "dynamic_int8", "static_int8", "static_smooth_int8"
177+
export BACKEND="default" # default, ipex
178+
export ITERS=100
179+
...
180+
181+
''''
182+
183+
$ bash pot_benchmark_qa.sh
184+
185+
Please note that, above shell script can perform optimization using IPEX to get Pytorch-(IPEX)-FP32 model
186+
or It can perform optimization/quantization using Intel® Neural Compressor to get Static-QAT-INT8,
187+
Static-Smooth-QAT-INT8 models. Moreover, you can choose the backend as `default` or `ipex` for INT8 models.
188+
189+
```
190+
191+
- Run quick inference to test the model output
192+
193+
```console
194+
$ python run_qa_inference.py --model_name_or_path=[FP32 or INT8 finetuned model] --model_type=["vanilla_fp32" or "quantized_int8"] --do_lower_case --keep_accents --ipex_enable
195+
196+
```
197+
198+
- Train/Infer/Benchmark TFIDF Embedding model for Scikit-Learn (Base) vs Intel® Extension for Scikit-Learn
199+
200+
```console
201+
$ cd nlp/feature_extractor
202+
203+
# train (.fit_transform func), infer (.transform func) and perform benchmark
204+
$ python run_benchmark_tfidf.py --course_dir=../../dataset/courses --is_preprocess
205+
206+
# now rerun but turn on Intel® Extension for Scikit-Learn
207+
$ python run_benchmark_tfidf.py --course_dir=../../dataset/courses --is_preprocess --intel_scikit_learn_enabled
208+
```
209+
210+
- Setup LEAP API
211+
212+
```console
213+
$ cd api
214+
215+
# install dependencies
216+
$ pip install -r requirements.txt
217+
218+
$ cd src/
219+
220+
# create a local vector store of course content for faster retrieval during inference
221+
# Here we get semantic or syntactic (TFIDF) embedding of each content from course and index it.
222+
$ python core/create_vector_index.py --course_dir=../../dataset/courses --emb_model_type=[semantic or syntactic] \
223+
--model_name_or_path=[Hugging face model name for semantic] --keep_accents
224+
225+
# update config.py
226+
$ cd ../
227+
$ vi config.py
228+
229+
''''
230+
ASK_DOUBT_CONFIG = {
231+
# hugging face BERT topology model name
232+
"emb_model_name_or_path": "ai4bharat/indic-bert",
233+
"emb_model_type": "semantic", #options: syntactic, semantic
234+
235+
# finetuned Extractive QA model path previously done
236+
"qa_model_name_or_path": "vanichandna/indic-bert-finetuned-squad",
237+
"qa_model_type": "vanilla_fp32", #options: vanilla_fp32, quantized_int8
238+
239+
# faiss index file path created previously
240+
"faiss_vector_index_path": "artifacts/index/faiss_emb_index"
241+
}
242+
...
243+
244+
''''
245+
246+
```
247+
248+
- For our Interactive Conversational AI Examiner component, as of now we are not doing any training as its based on
249+
recent Generative AI LLM (Large Language model) (open access models like LLaMA, Falcon etc.). You can update the API configuration by specifying hf_model_name (LLM name available in huggingface Hub). Please checkout https://huggingface.co/models
250+
251+
Here for performance gain, we can use INT8 quantized model optimized using Intel® Neural Compressor (Few options are like https://huggingface.co/decapoda-research/llama-7b-hf-int8 etc.)
252+
253+
Please Note that for fun 😄, we also provide usage of Azure OpenAI Cognitive Service to use models like GPT3 paid subscription API. You just need to provide `azure_deployment_name` below configuration and `<your_key>`
254+
255+
```console
256+
257+
AI_EXAMINER_CONFIG = {
258+
"llm_name": "azure_gpt3",
259+
"azure_deployment_name": "text-davinci-003-prod",
260+
"hf_model_name": "TheBloke/falcon-7b-instruct-GPTQ", # mosaicml/mpt-7b-instruct
261+
"device": 0, # cuda:0
262+
"llm_kwargs":{
263+
"do_sample": True,
264+
"temperature": 0.5,
265+
"max_new_tokens": 300,
266+
"top_p": 1.0,
267+
"top_k": 0,
268+
"repetition_penalty": 1.1,
269+
"num_return_sequences": 1,
270+
"stop_sequence": "<|endoftext|>"
271+
}
272+
```
273+
274+
- Start the API server
275+
276+
```console
277+
$ cd api/src/
278+
279+
# start the gunicorn server
280+
$ bash start.sh
281+
```
282+
283+
- Start the Streamlit web UI demo
284+
285+
```console
286+
$ cd webapp
287+
288+
# install dependencies
289+
$ pip install -r requirements.txt
290+
291+
$ streamlit run app.py
292+
293+
```
294+
295+
- Go to http://localhost:8502
296+
297+
# Benchmark Results with Intel® oneAPI AI Analytics Toolkit
298+
299+
- We have already added several benchmark results to compare how beneficial Intel® oneAPI AI Analytics Toolkit is compared to baseline. Please go to`benchmark` folder to view the results.
67300

68301
# What I learned ![image](https://user-images.githubusercontent.com/72274851/218499685-e8d445fc-e35e-4ab5-abc1-c32462592603.png)
69302

api/src/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
ASK_DOUBT_CONFIG = {
77
"emb_model_name_or_path": "ai4bharat/indic-bert",
88
"emb_model_type": "semantic", #options: syntactic, semantic
9-
"qa_model_name_or_path": "artifacts/model/indic-mALBERT-uncased",
9+
"qa_model_name_or_path": "vanichandna/indic-bert-finetuned-squad",
1010
"qa_model_type": "vanilla_fp32", #options: vanilla_fp32, quantized_int8
1111

1212
"intel_scikit_learn_enabled": True,
File renamed without changes.

0 commit comments

Comments
 (0)