Skip to content
Open
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
10 changes: 8 additions & 2 deletions scripts/train_eagle3_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,14 @@ def main():
.cuda()
.to(torch.bfloat16)
)
draft_model.load_embedding(args.target_model_path, embedding_key=args.embedding_key)
draft_model.freeze_embedding()
if (
not hasattr(draft_model_config, "target_hidden_size")
or draft_model_config.target_hidden_size == draft_model_config.hidden_size
):
Comment on lines +229 to +232
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This condition can be made more concise and idiomatic by using getattr with a default value. This avoids explicitly checking for the attribute's existence before accessing it.

On a related note, this entire conditional block is duplicated in scripts/train_eagle3_online.py. Consider refactoring the model setup logic into a shared utility function to improve maintainability and avoid future inconsistencies.

Suggested change
if (
not hasattr(draft_model_config, "target_hidden_size")
or draft_model_config.target_hidden_size == draft_model_config.hidden_size
):
if (
getattr(draft_model_config, "target_hidden_size", draft_model_config.hidden_size)
== draft_model_config.hidden_size
):

draft_model.load_embedding(
args.target_model_path, embedding_key=args.embedding_key
)
draft_model.freeze_embedding()
print_with_rank("Initialized draft model")

# build dataloaders
Expand Down
10 changes: 8 additions & 2 deletions scripts/train_eagle3_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,14 @@ def main():
.cuda()
.to(torch.bfloat16)
)
draft_model.load_embedding(args.target_model_path, embedding_key=args.embedding_key)
draft_model.freeze_embedding()
if (
not hasattr(draft_model_config, "target_hidden_size")
or draft_model_config.target_hidden_size == draft_model_config.hidden_size
):
Comment on lines +262 to +265
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This condition can be made more concise and idiomatic by using getattr with a default value. This avoids explicitly checking for the attribute's existence before accessing it.

On a related note, this entire conditional block is duplicated from scripts/train_eagle3_offline.py. Consider refactoring the model setup logic into a shared utility function to improve maintainability and avoid future inconsistencies.

Suggested change
if (
not hasattr(draft_model_config, "target_hidden_size")
or draft_model_config.target_hidden_size == draft_model_config.hidden_size
):
if (
getattr(draft_model_config, "target_hidden_size", draft_model_config.hidden_size)
== draft_model_config.hidden_size
):

draft_model.load_embedding(
args.target_model_path, embedding_key=args.embedding_key
)
draft_model.freeze_embedding()
print_with_rank("Initialized draft model")

# build dataloaders
Expand Down
15 changes: 8 additions & 7 deletions specforge/modeling/draft/llama3_eagle.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,14 +793,15 @@ def __init__(self, config, quant_config=None, attention_backend="sdpa") -> None:
)
self.midlayer = LlamaDecoderLayer(config, attention_backend=attention_backend)

self.hidden_size = config.hidden_size
if hasattr(config, "target_hidden_size"):
self.fc = torch.nn.Linear(
config.target_hidden_size * 3, config.hidden_size, bias=False
)
self.target_hidden_size = config.target_hidden_size
else:
self.fc = torch.nn.Linear(
config.hidden_size * 3, config.hidden_size, bias=False
)
self.target_hidden_size = config.hidden_size

self.fc = torch.nn.Linear(
self.target_hidden_size * 3, self.hidden_size, bias=False
)

self.norm = LlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
self.lm_head = nn.Linear(
Expand Down Expand Up @@ -874,7 +875,7 @@ def embed_input_ids(self, input_ids: torch.Tensor) -> torch.Tensor:

def project_hidden_states(self, hidden_states: torch.Tensor) -> torch.Tensor:
# eagle 3 requires hidden states from 3 layers
assert hidden_states.size(-1) == self.config.hidden_size * 3
assert hidden_states.size(-1) == self.target_hidden_size * 3
return self.fc(hidden_states)

def compute_logits(self, hidden_states: torch.Tensor) -> torch.Tensor:
Expand Down