Skip to content

Conversation

@fangpenlin
Copy link
Contributor

No description provided.

@github-actions
Copy link
Contributor

Changes

Name                  Lines    Diff    Tokens/Line    Diff
------------------  -------  ------  -------------  ------
tinygrad/tensor.py     1385      +6           20.5    -0.0


total lines changes: +6

return (self.maximum(0) - Y * self + (1 + self.abs().neg().exp()).log())._do_reduction(reduction)
log_exp = (1 + self.abs().neg().exp()).log()
base = self.maximum(0) - Y * self
if pos_weight is None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

can pos_weight be integrated so that there's only one return code path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedbacks. Can you elaborate a bit more what did you mean by that? Do you have an existing example in tinygrad doing so I can refer to?

Also, any rationale for doing so?

Copy link
Contributor Author

@fangpenlin fangpenlin Jun 19, 2025

Choose a reason for hiding this comment

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

I thought about it a bit, assuming that pos_weight is not provied, it's actually just [1, 1, 1, ...], i.e, all weights for the ration between positive and negative case is just one. If my understanding of what you want correctly, you want to have a pos_weight tensor as part of the UOps graph regardless if it's provided as an argument or not. Is that understanding correct? If so, yeah, I can make it so. Please let me know 🙏

As for rationale, I am not expert in terms of Tinygrad's compiler, but I guess doing so would make it much easier to optimize?

Copy link
Collaborator

Choose a reason for hiding this comment

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

we don't like if when it's not needed. unnecessary condition is hard to test well and maintain

@fangpenlin fangpenlin force-pushed the binary_crossentropy_logits_pos_weight branch from 03213a8 to 1318a2d Compare June 20, 2025 21:38
@chenyuxyz chenyuxyz merged commit 86d4585 into tinygrad:master Jun 24, 2025
36 checks passed
@fangpenlin fangpenlin deleted the binary_crossentropy_logits_pos_weight branch June 24, 2025 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants