Hritik commited on
Commit
cfe5653
1 Parent(s): 6ab097e

load on cpu for memory requirements

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -35,11 +35,14 @@ processor = MplugOwlProcessor(image_processor, tokenizer)
35
  model = MplugOwlForConditionalGeneration.from_pretrained(
36
  pretrained_ckpt,
37
  torch_dtype=torch.bfloat16,
38
- device_map={'':0}
 
39
  )
40
 
41
- for name, param in model.named_parameters():
42
- param.requires_grad = False
 
 
43
  peft_config = LoraConfig(
44
  target_modules=r'.*language_model.*\.(q_proj|v_proj|k_proj|o_proj|gate_proj|down_proj|up_proj)',
45
  inference_mode=True,
@@ -50,14 +53,14 @@ peft_config = LoraConfig(
50
  model = get_peft_model(model, peft_config)
51
  model.print_trainable_parameters()
52
  with open(trained_ckpt, 'rb') as f:
53
- ckpt = torch.load(f, map_location = torch.device(f"cuda:0"))
54
  model.load_state_dict(ckpt)
55
- model = model.to(torch.bfloat16)
56
  print('Model Loaded')
57
 
58
  PROMPT = """The following is a conversation between a curious human and AI assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.
59
  Human: <|video|>
60
- Human: Does this video entail the description: ""A basketball team walking off the field while the audience claps.""?
61
  AI: """
62
 
63
  valid_data = MultiModalDataset("examples/y5xuvHpDPZQ_000005_000015.mp4", PROMPT, tokenizer, processor, max_length = 256, loss_objective = 'sequential')
 
35
  model = MplugOwlForConditionalGeneration.from_pretrained(
36
  pretrained_ckpt,
37
  torch_dtype=torch.bfloat16,
38
+ device_map={'': 'cpu'}
39
+ # device_map={'':0}
40
  )
41
 
42
+ # for name, param in model.named_parameters():
43
+ # print(param.device)
44
+ # break
45
+
46
  peft_config = LoraConfig(
47
  target_modules=r'.*language_model.*\.(q_proj|v_proj|k_proj|o_proj|gate_proj|down_proj|up_proj)',
48
  inference_mode=True,
 
53
  model = get_peft_model(model, peft_config)
54
  model.print_trainable_parameters()
55
  with open(trained_ckpt, 'rb') as f:
56
+ ckpt = torch.load(f, map_location = torch.device("cpu"))
57
  model.load_state_dict(ckpt)
58
+ model = model.to("cuda:0").to(torch.bfloat16)
59
  print('Model Loaded')
60
 
61
  PROMPT = """The following is a conversation between a curious human and AI assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.
62
  Human: <|video|>
63
+ Human: Does this video entail the description: ""A soccer team walking off the field while the audience claps.""?
64
  AI: """
65
 
66
  valid_data = MultiModalDataset("examples/y5xuvHpDPZQ_000005_000015.mp4", PROMPT, tokenizer, processor, max_length = 256, loss_objective = 'sequential')