File size: 2,636 Bytes
15c46ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
--- a/vendor/nextgpt/code/header.py
+++ b/vendor/nextgpt/code/header.py
@@ -1,7 +1,11 @@
 import torch
 import datetime
 import types
-import deepspeed
+try:
+    import deepspeed
+except ImportError:
+    # DeepSpeed is only required by the upstream training entry points.
+    deepspeed = None
 from transformers.deepspeed import HfDeepSpeedConfig
 import transformers
 import numpy as np
@@ -26,7 +30,6 @@
 from copy import deepcopy
 import ipdb
 import argparse
-import data
 from transformers import LlamaTokenizer, LlamaForCausalLM, LlamaConfig
 from torch.nn.utils.rnn import pad_sequence
 from peft import LoraConfig, TaskType, get_peft_model
--- a/vendor/nextgpt/code/model/ImageBind/data.py
+++ b/vendor/nextgpt/code/model/ImageBind/data.py
@@ -23,7 +23,8 @@
 
 DEFAULT_AUDIO_FRAME_SHIFT_MS = 10  # in milliseconds
 
-BPE_PATH = "bpe/bpe_simple_vocab_16e6.txt.gz"
+from pathlib import Path
+BPE_PATH = str(Path(__file__).resolve().parent / "bpe" / "bpe_simple_vocab_16e6.txt.gz")
 
 
 def waveform2melspec(waveform, sample_rate, num_mel_bins, target_length):
--- a/vendor/nextgpt/code/model/__init__.py
+++ b/vendor/nextgpt/code/model/__init__.py
@@ -1,15 +1,15 @@
 import os.path
 from collections import OrderedDict
 
-from .agent import DeepSpeedAgent
 from .anyToImageVideoAudio import NextGPTModel
 import torch
 
 
 def load_model(args):
+    from .agent import DeepSpeedAgent
     agent_name = args['models'][args['model']]['agent_name']
     model_name = args['models'][args['model']]['model_name']
     model = globals()[model_name](**args)
 
-    agent = globals()[agent_name](model, args)
+    agent = {"DeepSpeedAgent": DeepSpeedAgent}[agent_name](model, args)
     return agent
--- a/vendor/nextgpt/code/model/anyToImageVideoAudio.py
+++ b/vendor/nextgpt/code/model/anyToImageVideoAudio.py
@@ -65,7 +65,8 @@
                                              self.args['vicuna_version'])
         print(f'Initializing language decoder from {self.vicuna_ckpt_path} ...')
 
-        self.llama_model = LlamaForCausalLM.from_pretrained(self.vicuna_ckpt_path)
+        self.llama_model = LlamaForCausalLM.from_pretrained(
+            self.vicuna_ckpt_path, torch_dtype=torch.float16, low_cpu_mem_usage=True)
         if self.args.get('freeze_lm'):
             print("Freezing the LLaMa ...")
             for param in self.llama_model.parameters():
@@ -727,7 +728,7 @@
             stopping_criteria=stopping_criteria,
             output_hidden_states=True,
             return_dict_in_generate=True,
-            output_attentions=True
+            output_attentions=False
         )
 
         output_embeddings = []