Skip to content

Commit 1760b52

Browse files
committed
fix: rustfmt, clippy lint, and gitignore .tldr
Apply rustfmt to demo_tui.rs. Fix clippy useless_vec lint in unit_tests.rs by adding explicit type annotation. Remove .tldr/ from tracking and add to .gitignore.
1 parent e230bf1 commit 1760b52

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Thumbs.db
3737
# Criterion benchmark output
3838
target/criterion/
3939

40+
# TLDR daemon cache
41+
.tldr/
42+
4043
# Web demo build artifacts
4144
web-demo/node_modules/
4245
web-demo/dist/

.tldr/status

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/demo_tui.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,7 @@ fn train_step(
185185
let logits = model.forward(input, Some(mask));
186186
let [b, t, v] = logits.dims();
187187

188-
let loss_fn = CrossEntropyLossConfig::new()
189-
.with_logits(true)
190-
.init(device);
188+
let loss_fn = CrossEntropyLossConfig::new().with_logits(true).init(device);
191189
let loss = loss_fn
192190
.forward(logits.reshape([b * t, v]), targets.reshape([b * t]))
193191
.mean();
@@ -387,8 +385,7 @@ fn run(
387385
_ => 15,
388386
};
389387
if last_tick.elapsed() >= Duration::from_millis(tick_ms) {
390-
let (new_model, loss) =
391-
train_step(model, &mut optim, &mask, &config, &device);
388+
let (new_model, loss) = train_step(model, &mut optim, &mask, &config, &device);
392389
model = new_model;
393390

394391
let (weights, norms) = extract_diagnostics(&model, &device);
@@ -409,7 +406,7 @@ fn ui(f: &mut Frame, app: &App) {
409406
Constraint::Length(1), // Title
410407
Constraint::Length(8), // Model + Training
411408
Constraint::Length(10), // Loss curve
412-
Constraint::Min(8), // Weights + Norms
409+
Constraint::Min(8), // Weights + Norms
413410
Constraint::Length(4), // Algorithm
414411
Constraint::Length(1), // Footer
415412
])
@@ -425,7 +422,10 @@ fn ui(f: &mut Frame, app: &App) {
425422

426423
fn draw_title(f: &mut Frame, area: Rect) {
427424
let title = Line::from(vec![
428-
Span::styled(" \u{03b1} ", Style::default().fg(Color::White).bg(ACCENT).bold()),
425+
Span::styled(
426+
" \u{03b1} ",
427+
Style::default().fg(Color::White).bg(ACCENT).bold(),
428+
),
429429
Span::raw(" "),
430430
Span::styled("AttnRes", Style::default().fg(Color::White).bold()),
431431
Span::styled(
@@ -446,7 +446,10 @@ fn draw_top_panels(f: &mut Frame, area: Rect, app: &App) {
446446
let model_text = vec![
447447
Line::from(vec![
448448
Span::styled(" d_model ", Style::default().fg(TEXT_MUTED)),
449-
Span::styled(format!("{}", app.d_model), Style::default().fg(Color::White)),
449+
Span::styled(
450+
format!("{}", app.d_model),
451+
Style::default().fg(Color::White),
452+
),
450453
]),
451454
Line::from(vec![
452455
Span::styled(" layers ", Style::default().fg(TEXT_MUTED)),
@@ -460,11 +463,17 @@ fn draw_top_panels(f: &mut Frame, area: Rect, app: &App) {
460463
]),
461464
Line::from(vec![
462465
Span::styled(" blocks ", Style::default().fg(TEXT_MUTED)),
463-
Span::styled(format!("{}", app.num_blocks), Style::default().fg(Color::White)),
466+
Span::styled(
467+
format!("{}", app.num_blocks),
468+
Style::default().fg(Color::White),
469+
),
464470
]),
465471
Line::from(vec![
466472
Span::styled(" heads ", Style::default().fg(TEXT_MUTED)),
467-
Span::styled(format!("{}", app.num_heads), Style::default().fg(Color::White)),
473+
Span::styled(
474+
format!("{}", app.num_heads),
475+
Style::default().fg(Color::White),
476+
),
468477
]),
469478
Line::from(vec![
470479
Span::styled(" d_ff ", Style::default().fg(TEXT_MUTED)),
@@ -480,10 +489,7 @@ fn draw_top_panels(f: &mut Frame, area: Rect, app: &App) {
480489
];
481490
let model_block = Paragraph::new(model_text).block(
482491
Block::default()
483-
.title(Span::styled(
484-
" Model ",
485-
Style::default().fg(ACCENT).bold(),
486-
))
492+
.title(Span::styled(" Model ", Style::default().fg(ACCENT).bold()))
487493
.borders(Borders::ALL)
488494
.border_style(Style::default().fg(BORDER)),
489495
);
@@ -504,7 +510,13 @@ fn draw_top_panels(f: &mut Frame, area: Rect, app: &App) {
504510
};
505511

506512
let speed_dots: String = (1..=5)
507-
.map(|i| if i <= app.speed { '\u{25cf}' } else { '\u{25cb}' })
513+
.map(|i| {
514+
if i <= app.speed {
515+
'\u{25cf}'
516+
} else {
517+
'\u{25cb}'
518+
}
519+
})
508520
.collect();
509521

510522
let pct = if app.max_steps > 0 {
@@ -774,10 +786,7 @@ fn draw_norms(f: &mut Frame, area: Rect, app: &App) {
774786
lines.push(Line::from(vec![
775787
Span::styled(label, Style::default().fg(TEXT_MUTED)),
776788
Span::styled(bar, Style::default().fg(ACCENT)),
777-
Span::styled(
778-
format!(" {:.3}", norm),
779-
Style::default().fg(TEXT_DIM),
780-
),
789+
Span::styled(format!(" {:.3}", norm), Style::default().fg(TEXT_DIM)),
781790
]));
782791
}
783792

tests/unit_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn test_attnres_weights_sum_to_one() {
270270
let config = AttnResConfig::new(32, 12, 4);
271271
let op = config.init_op::<TestBackend>(&device);
272272

273-
let blocks = vec![
273+
let blocks: Vec<Tensor<TestBackend, 3>> = vec![
274274
Tensor::random([2, 8, 32], Distribution::Normal(0.0, 1.0), &device),
275275
Tensor::random([2, 8, 32], Distribution::Normal(0.0, 1.0), &device),
276276
Tensor::random([2, 8, 32], Distribution::Normal(0.0, 1.0), &device),

0 commit comments

Comments
 (0)