Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick Fix Clip initializing issue in r2.0.0 (10585) into r2.0.0 #10633

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -424,26 +424,24 @@ def __init__(self, *args, **kwargs):
# TODO (yuya): need to handle post_process correctly in order to enable PP
self.output_dim = kwargs.pop('output_dim')
super().__init__(*args, **kwargs)
if self.post_process:
self.final_layernorm = TENorm(
config=self.config,
hidden_size=self.config.hidden_size,
eps=self.config.layernorm_epsilon,
)
self.head = torch.nn.Linear(
self.config.hidden_size,
self.output_dim,
bias=False,
)
self.final_layernorm = TENorm(
config=self.config,
hidden_size=self.config.hidden_size,
eps=self.config.layernorm_epsilon,
)
self.head = torch.nn.Linear(
self.config.hidden_size,
self.output_dim,
bias=False,
)

def forward(self, x):
x = super().forward(
x,
)
if self.post_process:
x = self.final_layernorm(x)
x = x[:, 0]
x = self.head(x)
x = self.final_layernorm(x)
x = x[:, 0]
x = self.head(x)
return x


Expand Down
2 changes: 1 addition & 1 deletion nemo/collections/vlm/neva/model/llava.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def convert_state(self, source, target):
"language_model.model.layers.*.post_attention_layernorm.weight": "language_model.decoder.layers.*.mlp.linear_fc1.layer_norm_weight",
"language_model.model.norm.weight": "language_model.decoder.final_layernorm.weight",
"language_model.lm_head.weight": "language_model.output_layer.weight",
"vision_tower.vision_model.*": "vision_model.vision_model.*",
"vision_tower.vision_model.**": "vision_model.vision_model.**",
}
if "vision_projection.encoder.linear_fc1.weight" in target.module.state_dict().keys():
mapping.update(
Expand Down
24 changes: 22 additions & 2 deletions nemo/lightning/io/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,28 @@ def call_transform(self, ctx: TransformCTX, *args, **kwargs):


def _match_keys(keys: List[str], pattern: str) -> np.ndarray:
regex_pattern = re.compile("^" + pattern.replace("*", r"([^.]+)") + "$")
wildcard_matches = [[] for _ in range(pattern.count("*"))]
escaped_pattern = ''
i = 0
wildcard_positions = []
while i < len(pattern):
if pattern[i : i + 2] == '**':
escaped_pattern += r'(.+)' # Match any characters including dots
wildcard_positions.append('**')
i += 2
elif pattern[i] == '*':
escaped_pattern += r'([^.]+)' # Match any characters except dots
wildcard_positions.append('*')
i += 1
else:
if pattern[i] == '.':
escaped_pattern += r'\.' # Escape the dot
else:
escaped_pattern += pattern[i]
i += 1

regex_pattern = re.compile("^" + escaped_pattern + "$")
num_wildcards = len(wildcard_positions)
wildcard_matches = [[] for _ in range(num_wildcards)]

for key in filter(lambda x: x is not None, keys):
match = regex_pattern.match(key)
Expand Down
Loading