Comments (9)
Hi! thanks for your contribution!, great first issue!
from torchmetrics.
Hi @SpirinEgor would it be possible for you to share some reproducible code?
from torchmetrics.
You can find metric code here. Since it is something like repo with further useful for me things, I add it to PyPI too. You can install it to your test dev and try inside the PyTorch Lightning module.
Btw, there are some simple tests. They work great without any failure.
from torchmetrics.
@SpirinEgor I must be doing something different from you, because if I call your metric inside training_step
I cannot reproduce the error. Could you provide what your training_step
looks like?
from torchmetrics.
Sure, here what I'm doing.
class MyModel(LightningModule):
def __init__(self, config: DictConfig, vocabulary: Vocabulary):
super().__init__()
...
pad_idx = vocabulary.label_to_id[PAD]
ignore_idx = [vocabulary.label_to_id[i] for i in [UNK, EOS, SOS] if i in vocabulary.label_to_id]
self._train_metrics = SequentialF1Score(mask_after_pad=True, pad_idx=pad_idx, ignore_idx=ignore_idx)
self._val_metrics = SequentialF1Score(
mask_after_pad=True, pad_idx=pad_idx, ignore_idx=ignore_idx, compute_on_step=False
)
self._test_metrics = SequentialF1Score(
mask_after_pad=True, pad_idx=pad_idx, ignore_idx=ignore_idx, compute_on_step=False
)
....
...
def training_step(self, batch: Tuple[torch.Tensor, dgl.DGLGraph], batch_idx: int) -> Dict: # type: ignore
labels, graph = batch
# [seq length; batch size; vocab size]
logits = self(graph, labels.shape[0], labels)
loss = self._calculate_loss(logits, labels)
prediction = logits.argmax(-1)
batch_metrics: ClassificationMetrics = self._train_metrics(prediction, labels) # **Error happens here**
log = {
"train/loss": loss,
"train/f1": batch_metrics.f1_score,
"train/precision": batch_metrics.precision,
"train/recall": batch_metrics.recall,
}
self.log_dict(log)
self.log("f1", batch_metrics.f1_score, prog_bar=True, logger=False)
return {"loss": loss}
def validation_step(self, batch: Tuple[torch.Tensor, dgl.DGLGraph], batch_idx: int) -> Dict: # type: ignore
labels, graph = batch
# [seq length; batch size; vocab size]
logits = self(graph, labels.shape[0], labels)
loss = self._calculate_loss(logits, labels)
prediction = logits.argmax(-1)
self._val_metrics(prediction, labels) # **And here**
return {"loss": loss}
This is very strange for me too. Because when I wrote tests for metric class it was work just fine...
I also tried to use the last version of PyTorch-Lightning, but it doesn't change anything.
from torchmetrics.
Strange, still cannot reproduce your error. Both training and validation seems to run fine :/
Do you have any backward hooks registered in your code? because it should only get to that location in the pytorch code if you have.
from torchmetrics.
Oh, it's become really tough...
I didn't define any hooks. Any chancing Lightning can do it? Also, I used DGL to train on graphs, maybe it defines hooks.
from torchmetrics.
I found the reason for all my troubles. In the main train function, I use WandbLogger
and I also use
wandb_logger.watch(model)
This step adds backward hooks to track gradients, their norms, etc. After I disable it metric start working as I expected.
Anyway, big thanks for your response! The library is great, hope to see more cool features.
from torchmetrics.
Thanks for letting me know, and glad that you like the library!
from torchmetrics.
Related Issues (20)
- Mean Average Detection ignores `warn_on_many_detections` set to False HOT 1
- `list` states leak (`Tensor`) memory HOT 1
- Behaviors of AUROC and Average Precision are inconsistent when all labels are equal HOT 4
- The default value of `compute_with_cache` should be `True` . HOT 2
- Bug in ERGAS HOT 2
- Ordinal classification metrics HOT 1
- Binary Classification Expected Calibration Error HOT 2
- `intersection_over_union` error HOT 2
- Clarify that nan is supported in zero_division HOT 4
- Add `_filter_kwargs` in `ClasswiseWrapper` metric wrapper HOT 3
- `MetricTracker` use `higher_is_better` as default for maximize HOT 2
- Unpredictable class order when `panoptic_quality(..., return_per_class=True)`
- torchmetrics Accuracy HOT 8
- BootStrapper.reset() does not reset properly
- segmentation.MeanIoU is wrong HOT 3
- DataLoader worker is killed in Docker HOT 4
- MeanAveragePrecision - bug in `max_detection_thresholds` HOT 3
- Documentation of ERGAS HOT 1
- Support for DLM (AIM) metric HOT 1
- Error for index tensor verification in GeneralizedDice if target is zeros HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from torchmetrics.