# New Contributor Looking for Mentorship on a pull request!

**URL:** <https://dev-discuss.pytorch.org/t/new-contributor-looking-for-mentorship-on-a-pull-request/3179>\
**Category:** Uncategorized\
**Created:** [August 13, 2025, 4:50pm UTC](https://dev-discuss.pytorch.org/t/new-contributor-looking-for-mentorship-on-a-pull-request/3179 "2025-08-13T16:50:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vulkomilev](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/vulkomilev/32/1431_2.png) [@vulkomilev](https://dev-discuss.pytorch.org/u/vulkomilev)\
**Post date:** [August 13, 2025, 4:50pm UTC](https://dev-discuss.pytorch.org/t/new-contributor-looking-for-mentorship-on-a-pull-request/3179/1 "2025-08-13T16:50:14Z")

</div>

Hi my name is Valko Milev and who’s passionate about contributing to PyTorch! But I need some guidance . I am currently fully employed and I am doing some ml projects on the side and unfortunately I don’t have enough time to explore the code base fully. I need some kind of mentorship/guidance to help finish one of my pull request. I am trying to finish this feature for several weeks but due to formentioned issues I have hard time doing so . Here is my pull request

> <https://github.com/pytorch/pytorch/issues/146643>
>
> \`\`\`py
> @torch.compile(dynamic=True)
> def fn(x):
> return torch.max(x, -1)
> \`\`\`
> ge…nerates the following code:
> \`\`\`py
> @triton.jit
> def triton\_red\_fused\_max\_0(in\_ptr0, out\_ptr0, out\_ptr1, ks0, xnumel, r0\_numel, XBLOCK : tl.constexpr, R0\_BLOCK : tl.constexpr):
> rnumel = r0\_numel
> RBLOCK: tl.constexpr = R0\_BLOCK
> xoffset = tl.program\_id(0) \* XBLOCK
> xindex = xoffset + tl.arange(0, XBLOCK)\[:, None\]
> xmask = xindex \< xnumel
> r0\_base = tl.arange(0, R0\_BLOCK)\[None, :\]
> rbase = r0\_base
> x0 = xindex
> \_tmp2 = tl.full(\[XBLOCK, R0\_BLOCK\], float("-inf"), tl.float32)
> \_tmp4 = tl.full(\[XBLOCK, R0\_BLOCK\], float("-inf"), tl.float32)
> \_tmp4\_index = tl.full(\[XBLOCK, R0\_BLOCK\], 9223372036854775807, tl.int64)
> for r0\_offset in range(0, r0\_numel, R0\_BLOCK):
> r0\_index = r0\_offset + r0\_base
> r0\_mask = r0\_index \< r0\_numel
> roffset = r0\_offset
> rindex = r0\_index
> r0\_1 = r0\_index
> tmp0 = tl.load(in\_ptr0 + (r0\_1 + ks0\*x0), xmask & r0\_mask, eviction\_policy='evict\_first', other=0.0)
> tmp1 = tl.broadcast\_to(tmp0, \[XBLOCK, R0\_BLOCK\])
> tmp3 = triton\_helpers.maximum(\_tmp2, tmp1)
> \_tmp2 = tl.where(r0\_mask & xmask, tmp3, \_tmp2)
> \_tmp4\_next, \_tmp4\_index\_next = triton\_helpers.maximum\_with\_index(
> \_tmp4, \_tmp4\_index, tmp1, rindex
> )
> \_tmp4 = tl.where(r0\_mask & xmask, \_tmp4\_next, \_tmp4)
> \_tmp4\_index = tl.where(r0\_mask & xmask, \_tmp4\_index\_next, \_tmp4\_index)
> tmp2 = triton\_helpers.max2(\_tmp2, 1)\[:, None\]
> tmp4\_val, tmp4\_idx = triton\_helpers.max\_with\_index(\_tmp4, \_tmp4\_index, 1)
> tmp4 = tmp4\_idx\[:, None\]
> tl.store(out\_ptr0 + (x0), tmp2, xmask)
> tl.store(out\_ptr1 + (x0), tmp4, xmask)
> \`\`\`
> 
> This could could be improved by doing:
> \`\`\`diff
> diff --git a/out.py b/out.py
> index 5d0acd594f7..5c3879867ed 100644
> \--- a/out.py
> +++ b/out.py
> @@ -8,7 +8,6 @@ def triton\_red\_fused\_max\_0(in\_ptr0, out\_ptr0, out\_ptr1, ks0, xnumel, r0\_numel, X
> r0\_base = tl.arange(0, R0\_BLOCK)\[None, :\]
> rbase = r0\_base
> x0 = xindex
> \- \_tmp2 = tl.full(\[XBLOCK, R0\_BLOCK\], float("-inf"), tl.float32)
> \_tmp4 = tl.full(\[XBLOCK, R0\_BLOCK\], float("-inf"), tl.float32)
> \_tmp4\_index = tl.full(\[XBLOCK, R0\_BLOCK\], 9223372036854775807, tl.int64)
> for r0\_offset in range(0, r0\_numel, R0\_BLOCK):
> @@ -19,15 +18,13 @@ def triton\_red\_fused\_max\_0(in\_ptr0, out\_ptr0, out\_ptr1, ks0, xnumel, r0\_numel, X
> r0\_1 = r0\_index
> tmp0 = tl.load(in\_ptr0 + (r0\_1 + ks0\*x0), xmask & r0\_mask, eviction\_policy='evict\_first', other=0.0)
> tmp1 = tl.broadcast\_to(tmp0, \[XBLOCK, R0\_BLOCK\])
> \- tmp3 = triton\_helpers.maximum(\_tmp2, tmp1)
> \- \_tmp2 = tl.where(r0\_mask & xmask, tmp3, \_tmp2)
> \_tmp4\_next, \_tmp4\_index\_next = triton\_helpers.maximum\_with\_index(
> \_tmp4, \_tmp4\_index, tmp1, rindex
> )
> \_tmp4 = tl.where(r0\_mask & xmask, \_tmp4\_next, \_tmp4)
> \_tmp4\_index = tl.where(r0\_mask & xmask, \_tmp4\_index\_next, \_tmp4\_index)
> \- tmp2 = triton\_helpers.max2(\_tmp2, 1)\[:, None\]
> tmp4\_val, tmp4\_idx = triton\_helpers.max\_with\_index(\_tmp4, \_tmp4\_index, 1)
> tmp4 = tmp4\_idx\[:, None\]
> + tmp2 = tmp4\_val\[:, None\]
> tl.store(out\_ptr0 + (x0), tmp2, xmask)
> tl.store(out\_ptr1 + (x0), tmp4, xmask)
> 
> \`\`\`
> because the \`argmax\` already compute the \`amax\`, so we don't need a separate reduction.
> 
> We could either:
> 1) Have a single two-output reduction op that does both \`amax+argmax\`
> 2) Combining the two at codegen time using the reduction cache. (We could use a DeferredLine, to swap between \`triton\_helpers.max\_with\_index\` and \`triton\_helpers.max2\` based on if the output is used.)
> 
> 
> 
> cc @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @amjames @desertfire @aakhundov

> <https://github.com/pytorch/pytorch/pull/159797>
>
> Fixes #146643
> 
> 
> cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @X…iaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @chenyang78 @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben
