Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
95 views12 pages

Mamba Code

Mamba code

Uploaded by

fish cant talk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views12 pages

Mamba Code

Mamba code

Uploaded by

fish cant talk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

AI VIET NAM – 2024

Text Classification with Mamba - Project


Minh-Duc Bui, Khai-Xuan Trinh, và Quang-Vinh Dinh

Ngày 25 tháng 2 năm 2024

Phần I: Giới thiệu


Gần đây, Mamba là kiến trúc mới ra mắt và được sự hưởng ứng mạnh mẽ từ cộng đồng các nhà nghiên
cứu. Mamba trở thành trend vì khả năng vượt trội hơn Transformer (kiến trúc phổ biến ở thời điểm
hiện tại). Sự vượt trội được thể hiện ở cả 3 tiêu chí chính để đánh giá 1 model: accuracy, speed, và
computional cost.

Trong project này, ta sẽ tìm hiểu cơ bản về kiến trúc Mamba và áp dụng Mamba vào bài toán text
classification.

1
AI VIETNAM aivietnam.edu.vn

Phần II: Nội dung


1. Mô tả dataset IMDB
IMDB dataset là bộ data bao gồm 50,000 đánh giá về phim. Đây là bộ dữ liệu được sử dụng cho
việc phân loại đánh giá tiêu cực và tích cực. Bộ dữ liệu được chia làm 2 phần bằng nhau, 25,000
mẫu để train, và 25,000 mẫu để kiểm thử. Bên cạnh đó, bộ dữ liệu cũng cung cấp 50,000 mẫu dữ
liệu chưa đánh nhãn để hỗ trợ quá trình train. Tuy nhiên trong project này ta chỉ sử dụng phần
dữ liệu đã được đánh nhãn để train model.

Hình 1: Ví dụ minh họa về dataset IMDB.

2. Model Mamba cho bài toán Text classification

(a) Install and import libraries: Đầu tiên ta sẽ install một số thư viện cần thiết của Hug-
gingface và Mamba:

1 ! pip install datasets evaluate accelerate


2 ! pip install causal - conv1d >=1.1.0
3 ! pip install mamba - ssm

Sau đó ta sẽ tiến hành login vào HuggingFace để download dataset và model có sẵn. Khi
chạy block code này thì HuggingFace sẽ đưa ra một đường dẫn đến trang HuggingFace để
lấy mã token. Lưu ý để thuận tiện cho quá trình train và đưa model lên Huggingface Hub
thì ta nên sử dụng token có quyền ghi của Huggingface.

1 from huggingface_hub import notebook_login


2 notebook_login ()

Cuối cùng ta sẽ import các thư viện chính được sử dụng trong phần này:

2
AI VIETNAM aivietnam.edu.vn

1 import os
2 import random
3 import json
4 import torch
5 import torch . nn as nn
6 from collections import namedtuple
7 from dataclasses import dataclass , field , asdict
8 from mamba_ssm . models . mixer_seq_simple import MambaLMHeadModel
9 from mamba_ssm . utils . hf import load_config_hf , load_state_dict_hf
10
11 import evaluate
12 import numpy as np
13 from datasets import load_dataset
14 from transformers import Trainer
15 from transformers import AutoTokenizer , TrainingArguments

(b) Download dataset:

1 # T ả i b ộ dataset
2 imdb = load_dataset ( " imdb " )

(c) Build Custom Mamba Model: Xây dựng model Mamba để phân loại văn bản.

3
AI VIETNAM aivietnam.edu.vn

• Setup config:

1 # Config class c ủ a Mamba


2 class MambaConfig :
3 d_model : int = 2560
4 n_layer : int = 64
5 vocab_size : int = 50277
6 ssm_cfg : dict = field ( default_factory = dict )
7 rms_norm : bool = True
8 residual_in_fp32 : bool = True
9 fused_add_norm : bool = True
10 p ad _v oc a b_ si z e _ mu lt i pl e : int = 8
11
12 def to_json_string ( self ) :
13 return json . dumps ( asdict ( self ) )
14
15 def to_dict ( self ) :
16 return asdict ( self )

• Định nghĩa class head (classifier) để phục vụ cho việc phân loại văn bản:

1 # Đ ị nh ngh ĩ a class head đ ể ph â n lo ạ i


2 class Ma m ba Cl as s if ic at i on He ad ( nn . Module ) :
3 def __init__ ( self , d_model , num_classes , ** kwargs ) :
4 super ( MambaClassificationHead , self ) . __init__ ()
5 # S ử d ụ ng m ộ t l ớ p tuy ế n t í nh đ ể th ự c hi ệ n ph â n lo ạ i d ự a tr ê n
đ ầ u v à o c ó k í ch th ư ớ c d_model v à num_classes c ầ n ph â n lo ạ i .
6 self . class ification_head = nn . Linear ( d_model , num_classes ,
** kwargs )
7
8 def forward ( self , hidden_states ) :
9 return self . classification_head ( hidden_states )

• Định nghĩa model Mamba:

1 class Ma m ba Te xt C la ss if i ca ti on ( MambaLMHeadModel ) :
2 def __init__ (
3 self ,
4 config : MambaConfig ,
5 initializer_cfg = None ,
6 device = None ,
7 dtype = None ,
8 ) -> None :
9 super () . __init__ ( config , initializer_cfg , device , dtype )
10

11 # T ạ o m ộ t đ ầ u ph â n lo ạ i s ử d ụ ng Ma mb a Cl as si f ic at i on He ad v ớ i
k í ch th ư ớ c đ ầ u v à o l à d_model v à s ố l ớ p l à 2.
12 self . classification_head = M am ba C la ss if i ca ti on H ea d ( d_model =
config . d_model , num_classes =2)
13
14 del self . lm_head
15
16 def forward ( self , input_ids , attention_mask = None , labels = None ) :

4
AI VIETNAM aivietnam.edu.vn

17 # Truy ề n input_ids qua model g ố c đ ể nh ậ n hidden_states .


18 hidden_states = self . backbone ( input_ids )
19

20 # L ấ y trung b ì nh c ủ a hidden_states theo chi ề u th ứ 2 đ ể t ạ o


ra [ CLS ] feature đ ạ i đ i ệ n
21 mean_hidden_states = hidden_states . mean ( dim =1)
22

23 # Đ ư a mean_hidden_states qua đ ầ u ph â n lo ạ i đ ể nh ậ n logits .


24 logits = self . classification_head ( mean_hidden_states )
25
26 if labels is None :
27 Classifi cationOutput = namedtuple ( " ClassificationOutp u t " ,
[ " logits " ])
28 return ClassificationOutput ( logits = logits )
29 else :
30 Classifi cationOutput = namedtuple ( " ClassificationOutp u t " ,
[ " loss " , " logits " ])
31

32 # S ử d ụ ng h à m m ấ t m á t CrossEntropyLoss đ ể t í nh loss .
33 loss_fct = nn . CrossEntropyLoss ()
34 loss = loss_fct ( logits , labels )
35
36 return ClassificationOutput ( loss = loss , logits = logits )
37
38 def predict ( self , text , tokenizer , id2label = None ) :
39 input_ids = torch . tensor ( tokenizer ( text ) [ ’ input_ids ’] ,
device = ’ cuda ’) [ None ]
40 with torch . no_grad () :
41 logits = self . forward ( input_ids ) . logits [0]
42 label = np . argmax ( logits . cpu () . numpy () )
43
44 if id2label is not None :
45 return id2label [ label ]
46 else :
47 return label
48
49 @classmethod
50 def from_pretrained ( cls , pretrained_model_name , device = None ,
dtype = None , ** kwargs ) :
51 # T ả i c ấ u h ì nh t ừ model đ ã đ ư ợ c train tr ư ớ c đ ó .
52 config_data = load_config_hf ( p retrai ned_m odel_n ame )
53 config = MambaConfig (** config_data )
54

55 # Kh ở i t ạ o model t ừ c ấ u h ì nh v à chuy ể n n ó đ ế n thi ế t b ị v à ki


ể u d ữ li ệ u mong mu ố n .
56 model = cls ( config , device = device , dtype = dtype , ** kwargs )
57

58 # T ả i tr ạ ng th á i model đ ã đ ư ợ c train tr ư ớ c đ ó .
59 model_state_dict = load_state_dict_hf ( pretrained_model_name ,
device = device , dtype = dtype )
60 model . load_state_dict ( model_state_dict , strict = False )
61

62 # In ra c á c tham s ố embedding m ớ i đ ư ợ c kh ở i t ạ o .
63 print ( " Newly initialized embedding : " , set ( model . state_dict ()
. keys () ) - set ( model_state_dict . keys () ) )
64 return model

• Cuối cùng ta sẽ tải trọng số và tokenizer của model Mamba đã được pretrain từ trước.

5
AI VIETNAM aivietnam.edu.vn

Trọng số của model Mamba pretrain sẽ không bao gồm các tham số của phần head
(classifier) MambaClassificationHead mà ta tự định nghĩa. Do đó, phần head này sẽ được
khởi tạo tham số từ đầu:

1 # T ả i model Mamba t ừ model đ ã đ ư ợ c train tr ư ớ c đ ó .


2 model = Ma mb aT e xt Cl a ss if ic a ti on . from_pretrained ( " state - spaces / mamba
-130 m " )
3 model . to ( " cuda " )
4

5 # T ả i tokenizer c ủ a model Mamba t ừ model gpt - neox -20 b .


6 tokenizer = AutoTokenizer . from_pretrained ( " EleutherAI / gpt - neox -20 b " )
7 # Đ ặ t id c ủ a token pad b ằ ng id c ủ a token eos trong tokenizer .
8 tokenizer . pad_token_id = tokenizer . eos_token_id

(d) Preprocess dataset: Trong phần này ta sẽ tiến hành tokenize dataset cho tập train và tập
test. Vì số lượng sample của tập test khá lớn nên để thuận tiện cho quá trình train ta sẽ lấy
ra 1 phần nhỏ của tập test để đánh giá model.

1 # T ạ o ch ứ c n ă ng ti ề n x ử l ý đ ể m ã h ó a v ă n b ả n v à c ắ t b ớ t c á c chu ỗ i kh ô ng
d à i h ơ n đ ộ d à i đ ầ u v à o t ố i đ a c ủ a m ã th ô ng b á o
2 def preprocess_function ( examples ) :
3 samples = tokenizer ( examples [ " text " ] , truncation = True )
4 # Kh ô ng c ầ n attention_mask
5 # C ụ th ể h ơ n v ề token masking c ủ a mamba c ó th ể tham kh ả o : https ://
github . com / state - spaces / mamba / issues /49
6 samples . pop ( ’ attention_mask ’)
7 return samples
8

9 # Th ự c hi ệ n m ã h ó a v ă n b ả n
10 tokenized_imdb = imdb . map ( preprocess_function , batched = True )
11

12 # Set seed cho h à m random


13 random . seed (42)
14

15 # T ạ o t ậ p train v à test
16 train_dataset = tokenized_imdb [ " train " ]
17 test_dataset = tokenized_imdb [ " test " ]
18

19 # T ạ o t ậ p evaluation đ ể đ á nh gi á trong l ú c train


20 # Do s ố l ư ợ ng t ậ p test l ớ n n ê n ch ỉ l ấ y m ẫ u 1% t ậ p d ữ li ệ u test đ ể đ á nh
gi á
21 total_samples = len ( test_dataset )
22 eval_samples = int (0.1 * total_samples )
23 eval_indices = random . sample ( range ( total_samples ) , eval_samples )
24 eval_dataset = test_dataset . select ( eval_indices )

(e) Evaluation metric: Để đánh giá performance của model ta sẽ sử dụng metric accuracy từ
thư viện evaluate:

1 # T ả i module " accuracy " t ừ th ư vi ệ n evaluate .


2 accuracy = evaluate . load ( " accuracy " )
3

6
AI VIETNAM aivietnam.edu.vn

4 # Đ ị nh ngh ĩ a h à m compute_metrics đ ể t í nh c á c đ ộ đ o hi ệ u su ấ t ( metrics )


cho vi ệ c đ á nh gi á model .
5 def compute_metrics ( eval_pred ) :
6 predictions , labels = eval_pred
7

8 # L ấ y ch ỉ s ố c ủ a l ớ p c ó x á c su ấ t cao nh ấ t trong predictions .


9 predictions = np . argmax ( predictions , axis =1)
10

11 # S ử d ụ ng module " accuracy " đ ể t í nh đ ộ ch í nh x á c d ự a tr ê n


predictions v à labels .
12 return accuracy . compute ( predictions = predictions , references = labels )

(f) Train model: Sau khi đã chuẩn bị xong dataset, ta sẽ tiến hành setup một số tham số trong
quá trình train và tiến hành train model.
• Trước hết, ta sẽ định nghĩa một số hyper-parameter mà ta sẽ sử dụng để train model:

1 # Đ ị nh ngh ĩ a t ê n project đ ể log th ô ng tin qu á tr ì nh train tr ê n wandb


2 # os . environ [" WANDB_PROJECT "] = " mamba_tutorial "
3

4 # Đ ị nh ngh ĩ a c á c tham s ố train trong class TrainingArguments .


5 # C ụ th ể h ơ n v ề c á c tham s ố h ỗ tr ợ c ó th ể tham kh ả o : https ://
huggingface . co / docs / transformers / main_classes / trainer
6 training_args = TrainingArguments (
7 output_dir = " m a m b a_ t e x t _ c l a s s if i c a t i o n " , # T ê n folder output
8 learning_rate =5 e -5 ,
9 p e r _ d e v i c e _ t r a i n _ b a t c h _ s i z e =4 , # S ố l ư ợ ng train sample tr ê n m ỗ i
device
10 p e r _ d e v i c e _ e v a l _ b a t c h _ s i z e =16 , # S ố l ư ợ ng eval sample tr ê n m ỗ i
device
11 num_train_epochs =1 , # S ố epoch train
12 warmup_ratio =0.01 , # T ỉ l ệ t ă ng d ầ n lr trong giai đ o ạ n warmup
13 lr_scheduler_type = " cosine " , # Lo ạ i scheduler đ ể gi ả m lr
14 report_to = " none " , # " wandb " n ế u mu ố n log k ế t qu ả
15 evaluation_strategy = " steps " , # X á c đ ị nh metric đ á nh gi á sau m ỗ i
số bước
16 eval_steps =0.1 , # S ố b ư ớ c gi ữ a c á c đ ợ t đ á nh gi á
17 save_strategy = " steps " , # X á c đ ị nh khi n à o l ư u checkpoint
18 save_steps =0.1 , # S ố b ư ớ c gi ữ a c á c l ầ n l ư u checkpoint
19 logging_strategy = " steps " , # X á c đ ị nh khi n à o in th ô ng tin log
20 logging_steps =1 , # S ố b ư ớ c gi ữ a c á c l ầ n in th ô ng tin log
21 push_to_hub = True , # Đ ẩ y k ế t qu ả l ê n Hub
22 lo ad _be st _mo de l _a t_e nd = True , # Load model c ó k ế t qu ả evaluation
t ố t nh ấ t trong qu á tr ì nh train
23 )

• Sau đó ta sẽ khởi tạo class MambaTrainer kế thừa từ class Trainer. Đầu tiên, ta sẽ tạo hàm
compute_loss() để định nghĩa hàm loss sử dụng trong quá trình train. Vì ta đã triển khai
hàm loss là cross-entropy trong hàm forward của model, nên ta chỉ cần trích xuất giá trị
mất mát từ kết quả trả về của hàm forward. Sau đó ta sẽ tiếp tục code hàm save_model()
để định nghĩa cách lưu model. Để lưu model, ta cần ghi lại các tham số, tokenizer, và
cấu hình (config) của model.

7
AI VIETNAM aivietnam.edu.vn

1 # Đ ị nh ngh ĩ a m ộ t class MambaTrainer k ế th ừ a t ừ class Trainer .


2 class MambaTrainer ( Trainer ) :
3

4 # Đ ị nh ngh ĩ a h à m compute_loss đ ể t í nh to á n h à m m ấ t m á t trong qu á


tr ì nh train .
5 def compute_loss ( self , model , inputs , return_outputs = False ) :
6 # L ấ y gi á tr ị input_ids v à labels t ừ inputs .
7 input_ids = inputs . pop ( " input_ids " )
8 labels = inputs . pop ( ’ labels ’)
9

10 # G ọ i h à m forward c ủ a model v ớ i input_ids v à labels đ ể nh ậ n


c á c k ế t qu ả .
11 outputs = model ( input_ids = input_ids , labels = labels )
12

13 # L ấ y gi á tr ị loss t ừ k ế t qu ả c ủ a model .
14 loss = outputs . loss
15

16 # Tr ả v ề c ả loss v à outputs n ế u return_outputs l à True , ng ư ợ


c l ạ i ch ỉ tr ả v ề loss .
17 return ( loss , outputs ) if return_outputs else loss
18

19 # Đ ị nh ngh ĩ a h à m save_model đ ể l ư u model trong qu á tr ì nh train .


20 def save_model ( self , output_dir = None , _internal_call = False ) :
21 # Ki ể m tra n ế u th ư m ụ c l ư u tr ữ kh ô ng đ ư ợ c ch ỉ đ ị nh , s ử d ụ ng
th ư m ụ c m ặ c đ ị nh t ừ đ ố i s ố ’ args ’.
22 if output_dir is None :
23 output_dir = self . args . output_dir
24

25 # N ế u th ư m ụ c đ ầ u ra kh ô ng t ồ n t ại , t ạ o m ớ i n ó .
26 if not os . path . exists ( output_dir ) :
27 os . makedirs ( output_dir )
28

29 # L ư u tr ạ ng th á i c ủ a model PyTorch v à o file ’ pytorch_model .


bin ’ trong th ư m ụ c đ ầ u ra .
30 torch . save ( self . model . state_dict () , f " { output_dir }/
pytorch_model . bin " )
31

32 # L ư u tr ạ ng th á i c ủ a tokenizer v à o th ư m ụ c đ ầ u ra .
33 self . tokenizer . save_pretrained ( output_dir )
34

35 # L ư u c ấ u h ì nh c ủ a model v à o file ’ config . json ’ trong th ư m ụ


c đ ầ u ra .
36 with open ( f ’{ output_dir }/ config . json ’ , ’w ’) as f :
37 json . dump ( self . model . config . to_dict () , f )

• Cuối cùng ta sẽ khởi tạo class MambaTrainer, đây là class chính để train model. Sau khi đã
khởi tạo thì ta chỉ cần gọi trainer.train() thì quá trình train model sẽ được tiến hành:

1 # Kh ở i t ạ o classs MambaTrainer đ ể th ự c hi ệ n qu á tr ì nh train c ủ a


model .
2 trainer = MambaTrainer (
3 model = model , # Model c ầ n train
4 train_dataset = train_dataset , # D ữ li ệ u train
5 eval_dataset = eval_dataset , # D ữ li ệ u đ á nh gi á

8
AI VIETNAM aivietnam.edu.vn

6 tokenizer = tokenizer , # Tokenizer s ử d ụ ng đ ể m ã h ó a d ữ li ệ u


7 args = training_args , # C á c tham s ố train đ ã đ ư ợ c đ ị nh ngh ĩ a tr ư ớ c
đó
8 compute_metrics = compute_metrics # H à m t í nh c á c đ ộ đ o hi ệ u su ấ t (
metrics ) cho đ á nh gi á
9 )
10 # B ắ t đ ầ u qu á tr ì nh train b ằ ng c á ch g ọ i h à m train () tr ê n classs
trainer .
11 trainer . train ()

• Sau khi quá trình train hoàn tất, ta sẽ đưa weight, config của model lên HuggingFace
Hub để lưu lại:

1 # Đ ẩ y model l ê n huggingface hub


2 trainer . push_to_hub ( commit_message = " Training complete " )
3
4 >> Output : CommitInfo ( commit_url = ’ https :// huggingface . co /
trinhxuankhai / m a m ba _ t e x t _ c l a s si f i c a t i o n / commit /816827
a e 9 1 a 9 1 d d 9 0 0 6 a 9 e f 6 6 e c e f d 8 3 7 3 8 2 9 9 8 b ’ , commit_message = ’ Training
complete ’ , commit_description = ’ ’ , oid = ’ 816827
a e 9 1 a 9 1 d d 9 0 0 6 a 9 e f 6 6 e c e f d 8 3 7 3 8 2 9 9 8 b ’ , pr_url = None , pr_revision =
None , pr_num = None )

(g) Run Testing: Sau khi đã hoàn tất quá trình train, ta sẽ đánh giá model trên tập test và in
ra kết quả đánh giá của model:

1 # Th ự c hi ệ n d ự đ o á n tr ê n t ậ p d ữ li ệ u validation
2 outputs = trainer . predict ( test_dataset )
3 print ( outputs . metrics )
4
5 >> Output : { ’ test_loss ’: 0.21128389239311218 , ’ test_accuracy ’: 0.94708 ,
’ test_runtime ’: 1308.2019 , ’ t es t_ sa m pl es _ pe r_ se c on d ’: 19.11 , ’
tes t_step s_per_ sec on d ’: 1.195}

9
AI VIETNAM aivietnam.edu.vn

(h) Load and inference model from Hub: Ở phần trước, sau khi ta đưa model lên Hugging-
face Hub, nếu muốn inference model ta có thể gọi hàm from_pretrained của model Mamba ta
đã định nghĩa ở trước để load pretrain model. Sau đó ta sẽ truyền văn bản cần phân loại,
tokenize và id của từng class vô hàm predict của model để thực hiện dự đoán kết quả.

1 # T ả i model Mamba t ừ model đ ã đ ư ợ c train tr ư ớ c đ ó .


2 model = Ma mb aT e xt Cl a s s if ic a ti on . from_pretrained ( " trinhxuankhai /
m a m b a _ te x t _ c l a s s i fi c a t i o n " )
3 model . to ( " cuda " )
4

5 # T ả i tokenizer c ủ a model Mamba t ừ model đ ã đ ư ợ c train tr ư ớ c đ ó .


6 tokenizer = AutoTokenizer . from_pretrained ( " trinhxuankhai /
m a m b a _ te x t _ c l a s s i fi c a t i o n " )
7 # Đ ặ t id c ủ a token pad b ằ ng id c ủ a token eos trong tokenizer .
8 tokenizer . pad_token_id = tokenizer . eos_token_id

Sau đây ta sẽ chạy thử một sample trên tập test:

1 id2label = {0: " NEGATIVE " , 1: " POSITIVE " }


2 text = imdb [ ’ test ’ ][0][ ’ text ’]
3 label = imdb [ ’ test ’ ][0][ ’ label ’]
4 response = model . predict ( text , tokenizer , id2label )
5 print ( f ’ Classify : { text }\ nGT : { id2label [ label ]}\ nPredict : { response } ’)
6
7 >> Output :
8 - Classify : I love sci - fi and am willing to put up with a lot . Sci - fi
movies / TV are usually underfunded , under - appreciated and
misunderstood . I tried to like this , I really did , but it is to good
TV sci - fi as Babylon 5 is to Star Trek ( the original ) .
9 - GT : NEGATIVE
10 - Predict : NEGATIVE

10
AI VIETNAM aivietnam.edu.vn

Phần III: Câu hỏi trắc nghiệm


1. Trong state space model, dạng recurrent phù hợp cho quá trình inference vì?
(a) Khả năng tính toán song song.
(b) Độ phức tạp O(n2 ).
(c) Độ phức tạp O(n).
(d) Khả năng xử lý long sequence.

2. Trong state space model, dạng convolutional có tính chất nào sau đây?
(a) Độ phức tạp O(n2 ).
(b) Không thể tính toán song song.
(c) Khả năng tính toán song song.
(d) Khả năng attention.

3. Trong structured state space model (S4), ma trận HiPPO được sử dụng để khởi tạo ma trận A vì:
(a) Khả năng tính toán song song.
(b) Tăng tham số để model học.
(c) Giảm tham số để model học.
(d) Tăng khả năng ghi nhớ sequence.

4. Trong state space model, biểu thức Dxt trong công thức yt = Cht + Dxt đóng vai trò gì?
(a) Activation function.
(b) LayerNorm.
(c) Skip-connection.
(d) BatchNorm.

5. Trong state space model, ta chỉ có thể sử dụng dạng recurrent để inference là nhận định:
(a) True
(b) False

6. Trong state space model, dạng convolutional phù hợp để train vì độ phức tạp O(n) so với O(n2 )
của dạng recurrent là nhận định:
(a) True
(b) False

7. Trong state space model, dạng convolutional phù hợp để train vì khả năng tính toán song song là
nhận định:
(a) True
(b) False

8. Trong state space model, dạng recurrent phù hợp để inference vì có khả năng tính toán song song
là nhận định:
(a) True
(b) False

11
AI VIETNAM aivietnam.edu.vn

9. Trong state space model, dạng recurrent phù hợp để inference vì độ phức tạp O(1) khi tạo ra từng
token là nhận định:
(a) True
(b) False

10. Đâu là contribution của Mamba?


(a) Khả năng tính toán song song ở dạng convolutional.
(b) Khả năng tính toán song song ở dạng recurrent.
(c) Khả năng tính toán song song ở 2 dạng convolutional và recurrent.
(d) Khả năng tính toán song song khi inference.

11. Đâu là contribution của Mamba?


(a) Khả năng tạo ra trọng số phụ thuộc vào input
(b) Khả năng tạo ra trọng số không dựa vào input.
(c) Khả năng tạo ra trọng số phụ thuộc vào label.
(d) Khả năng tạo ra trọng số không phụ thuộc vào label.

- Hết -

12

You might also like