huggingface / huggingface/candle

Assigning value to Tensor(translate torch expression to Candle)

Open
#2,344 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
21k
Forks
1.8k
Avg merge
16h 42m
Merged PRs (30d)
25

Description

Hi, how should I translate this expression from Python(torch) to candle:
Both count, mask and result are tensors:
```
mask = (count.squeeze(-1) > 0)
result[mask] = result[mask] / count[mask].repeat(1, C)
```

I tried it this way, but it seems wrong:

```
let mask = count.squeeze(D::Minus1)?.gt(0 as i64)?;
let masked_ans_result = ans_result.i(&mask)?;
let repeated_ans_count = ans_count.i(&mask)?.repeat(&[c])?;
let updated_ans_result = masked_ans_result.div(&repeated_ans_count)?;
ans_result.i(&mask)?.eq( &updated_ans_result)?;
```

Contributor guide

No contributing guide indexed for this repository

Research direction

No repository file or test is named; the issue only provides Python/PyTorch and Rust/Candle snippets. Start by checking Candle's tensor indexing and assignment APIs, then verify that the translated operation updates the selected result values and preserves the original masking and repeat behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
pytorch, rust
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.