Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
siddk committed Aug 21, 2023
1 parent b30616f commit 7ed3adc
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions open_flamingo/src/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,23 @@ def create_model_and_transforms(
Tokenizer: A tokenizer for the language model
"""
vision_encoder, _, image_processor = open_clip.create_model_and_transforms(
clip_vision_encoder_path, pretrained=clip_vision_encoder_pretrained, cache_dir=cache_dir
clip_vision_encoder_path,
pretrained=clip_vision_encoder_pretrained,
cache_dir=cache_dir,
)
# set the vision encoder to output the visual features
vision_encoder.visual.output_tokens = True

text_tokenizer = AutoTokenizer.from_pretrained(
tokenizer_path, local_files_only=use_local_files, trust_remote_code=True, cache_dir=cache_dir
tokenizer_path,
local_files_only=use_local_files,
trust_remote_code=True,
cache_dir=cache_dir,
)
# add Flamingo special tokens to the tokenizer
text_tokenizer.add_special_tokens({"additional_special_tokens": ["<|endofchunk|>", "<image>"]})
text_tokenizer.add_special_tokens(
{"additional_special_tokens": ["<|endofchunk|>", "<image>"]}
)
if text_tokenizer.pad_token is None:
# Issue: GPT models don't have a pad token, which we use to
# modify labels for the loss.
Expand Down Expand Up @@ -87,7 +94,9 @@ def set_input_embeddings(self, new_embeddings):
lang_encoder,
text_tokenizer.encode("<|endofchunk|>")[-1],
text_tokenizer.encode("<image>")[-1],
vis_dim=open_clip.get_model_config(clip_vision_encoder_path)["vision_cfg"]["width"],
vis_dim=open_clip.get_model_config(clip_vision_encoder_path)["vision_cfg"][
"width"
],
cross_attn_every_n_layers=cross_attn_every_n_layers,
**flamingo_kwargs,
)
Expand Down

0 comments on commit 7ed3adc

Please sign in to comment.