MCPcopy Create free account
hub / github.com/Alpha-VLLM/LLaMA2-Accessory / main

Function main

SPHINX/inference.py:8–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6
7
8def main() -> None:
9 world_size = int(os.environ['WORLD_SIZE'])
10 rank = int(os.environ["RANK"])
11 dist.init_process_group(
12 world_size=world_size, rank=rank,
13 backend="nccl", init_method=f"env://",
14 )
15 torch.cuda.set_device(rank)
16
17 # mp_group tells the model which ranks will work together
18 # through model parallel to compose a complete model.
19 # When mp_group is None, a single-rank process group will
20 # be created and used, which means model parallel size = 1 (not enabled)
21 model = SPHINXModel.from_pretrained(
22 pretrained_path="/path/to/pretrained", with_visual=True,
23 mp_group=dist.new_group(ranks=list(range(world_size)))
24 )
25 # You may also, say, launch 4 processes and make [0,1] and [2,3] ranks to form mp groups, respectively.
26
27 # it's important to make sure that ranks within the same
28 # model parallel group should always receive the same input simultaneously
29 image = Image.open("examples/1.jpg")
30 qas = [["What's in the image?", None]]
31
32 response = model.generate_reponse(qas, image, max_gen_len=1024, temperature=0.9, top_p=0.5, seed=0)
33 print(response)
34
35 # if you wanna continue
36 qas[-1][-1] = response
37 qas.append(["Then how does it look like?", None])
38 response2 = model.generate_reponse(qas, image, max_gen_len=1024, temperature=0.9, top_p=0.5, seed=0)
39 print(response2)
40
41
42if __name__ == "__main__":

Callers 1

inference.pyFile · 0.70

Calls 2

printFunction · 0.85
from_pretrainedMethod · 0.80

Tested by

no test coverage detected