Skip to content

Commit 1ed2fec

Browse files
committed
Fix format.
Signed-off-by: menogrey <1299267905@qq.com>
1 parent 7780147 commit 1ed2fec

8 files changed

Lines changed: 49 additions & 14 deletions

File tree

scripts/prepare_hidden_states.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,8 @@ def generate(
507507
continue
508508

509509
filtered_batch_gpu = {
510-
k: v.to(get_local_device(), non_blocking=True) for k, v in filtered_batch.items()
510+
k: v.to(get_local_device(), non_blocking=True)
511+
for k, v in filtered_batch.items()
511512
}
512513
_, _, aux_hidden_states_list, last_hidden_states_list = self.model.extend(
513514
**filtered_batch_gpu,

scripts/train_eagle3.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ def print_cuda_memory_debug(label: str) -> None:
7373
allocated_bytes = device_module.memory_allocated()
7474
reserved_bytes = device_module.memory_reserved()
7575
except Exception as exc:
76-
print(f"[memory-debug] {label}: failed to query {device_type} memory: {exc}", flush=True)
76+
print(
77+
f"[memory-debug] {label}: failed to query {device_type} memory: {exc}",
78+
flush=True,
79+
)
7780
return
7881

7982
rank = dist.get_rank() if dist.is_available() and dist.is_initialized() else "NA"
@@ -762,7 +765,10 @@ def run_forward(
762765
# pixel_values = [pv.to(get_local_device()) for pv in data["pixel_values"]] if args.is_vlm else None
763766
if args.is_vlm:
764767
image_grid_thw = (
765-
[thw.to(get_local_device()).squeeze() for thw in data["image_grid_thw"]]
768+
[
769+
thw.to(get_local_device()).squeeze()
770+
for thw in data["image_grid_thw"]
771+
]
766772
if args.is_vlm
767773
else None
768774
)
@@ -831,7 +837,9 @@ def run_forward(
831837
target=target,
832838
hidden_states=hidden_states,
833839
position_ids=(
834-
data["position_ids"].to(get_local_device()) if "position_ids" in data else None
840+
data["position_ids"].to(get_local_device())
841+
if "position_ids" in data
842+
else None
835843
),
836844
image_grid_thw=image_grid_thw,
837845
is_vlm=args.is_vlm,

specforge/benchmarks/benchmark_flex_attention.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
LlamaFlexAttention,
1414
prepare_decoder_attention_mask,
1515
)
16-
from specforge.utils import empty_cache, get_device_module, get_device_type, get_local_device, synchronize
16+
from specforge.utils import (
17+
empty_cache,
18+
get_device_module,
19+
get_device_type,
20+
get_local_device,
21+
synchronize,
22+
)
1723

1824
dynamo.config.recompile_limit = 64
1925

specforge/benchmarks/benchmark_loss.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33

44
import torch
55

6-
from specforge.core.loss import log_softmax_loss, _compute_loss
7-
from specforge.utils import empty_cache, get_device_module, get_device_type, get_local_device, synchronize
6+
from specforge.core.loss import _compute_loss, log_softmax_loss
7+
from specforge.utils import (
8+
empty_cache,
9+
get_device_module,
10+
get_device_type,
11+
get_local_device,
12+
synchronize,
13+
)
814

915
TTT_LENGTH = 7
1016

@@ -31,13 +37,20 @@ def benchmark_loss_method(
3137
target = torch.softmax(
3238
torch.randn(B, T, V, device=get_local_device(), dtype=torch.float32), dim=-1
3339
)
34-
position_mask = torch.ones((B, T, 1), dtype=torch.bool, device=get_local_device())
40+
position_mask = torch.ones(
41+
(B, T, 1), dtype=torch.bool, device=get_local_device()
42+
)
3543

3644
# Pre-allocate logits tensors for each TTT step
3745
logits_list = []
3846
for i in range(TTT_LENGTH):
3947
logits = torch.randn(
40-
B, T, V, device=get_local_device(), requires_grad=True, dtype=torch.float32
48+
B,
49+
T,
50+
V,
51+
device=get_local_device(),
52+
requires_grad=True,
53+
dtype=torch.float32,
4154
)
4255
logits_list.append(logits)
4356

specforge/core/eagle3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from specforge.core.lk_loss import compute_acceptance_rate, compute_lk_loss
3636
from specforge.core.loss import log_softmax_loss
3737
from specforge.modeling.draft import Eagle3DraftModel
38-
from specforge.utils import get_compile_backend, empty_cache, padding
38+
from specforge.utils import empty_cache, get_compile_backend, padding
3939

4040

4141
class Eagle3Model(nn.Module):

specforge/distributed.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ def init_distributed(
7878
timeout(int): Timeout for collective communication in minutes
7979
tp_size(int): The degree of tensor parallelism
8080
"""
81-
dist.init_process_group(backend=get_dist_backend(), timeout=timedelta(minutes=timeout))
81+
dist.init_process_group(
82+
backend=get_dist_backend(), timeout=timedelta(minutes=timeout)
83+
)
8284
local_rank = dist.get_rank() % device_count()
8385
set_device(local_rank)
8486
print_with_rank(f"bind to device {local_rank}")
@@ -123,7 +125,9 @@ def init_distributed(
123125
_DP_GROUP = dp_group
124126
_DRAFT_DP_GROUP = draft_device_mesh.get_group("draft_dp")
125127
_DRAFT_SP_GROUP = draft_device_mesh.get_group("sp")
126-
_DP_DEVICE_MESH = dist.DeviceMesh.from_group(dp_group, device_type=get_device_type())
128+
_DP_DEVICE_MESH = dist.DeviceMesh.from_group(
129+
dp_group, device_type=get_device_type()
130+
)
127131

128132

129133
def destroy_distributed():

specforge/modeling/auto.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
modeling_utils,
1919
)
2020

21+
from specforge.utils import get_local_device
22+
2123
from .draft.llama3_eagle import LlamaForCausalLMEagle3
2224
from .target.custom_backend import (
2325
GptOssForCausalLM,
@@ -28,7 +30,6 @@
2830
Qwen3ForCausalLM,
2931
Qwen3MoeForCausalLM,
3032
)
31-
from specforge.utils import get_local_device
3233

3334

3435
class AutoEagle3DraftModel(AutoModelForCausalLMBase):

specforge/modeling/draft/flex_attention.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def __new__(cls, *args, **kwargs):
7777
@torch.compiler.disable(recursive=False)
7878
def __init__(self):
7979
if not self._is_create_block_mask_compiled:
80-
self._compiled_create_block_mask = torch.compile(create_block_mask, backend=get_compile_backend())
80+
self._compiled_create_block_mask = torch.compile(
81+
create_block_mask, backend=get_compile_backend()
82+
)
8183
self._is_create_block_mask_compiled = True
8284

8385
def __call__(self):

0 commit comments

Comments
 (0)