Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

MPC Quantized Machine Learning- Jacobi SVD #952

Closed
wants to merge 1 commit into from

Conversation

BingLiu0
Copy link

MPC Quantized Machine Learning- Jacobi SVD

Pull Request

What problem does this PR solve?

Issue Number: Fixed #

Possible side effects?

  • Performance:

  • Backward compatibility:

MPC Quantized Machine Learning- Jacobi SVD
Copy link


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@deadlywing deadlywing self-requested a review January 2, 2025 03:30
Copy link

github-actions bot commented Feb 1, 2025

Stale pull request message. Please comment to remove stale tag. Otherwise this pr will be closed soon.

Copy link
Contributor

@deadlywing deadlywing left a comment

Choose a reason for hiding this comment

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

  1. 需要在tests文件夹内增加jacobi_test.py文件
  2. python文件请格式化,推荐的工具参考这里

S = (A + A.T) / 2
return S

n = 10
Copy link
Contributor

Choose a reason for hiding this comment

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

算法实现的文件中不要出现这种全局的测试,你可以在tests/jacobi_test.py中测试明文实现 或者 密态精度

A, _, final_iterations = lax.fori_loop(0, max_iter, body_fun, (A, max_off_diag, iterations))

singular_values = jnp.abs(jnp.diag(A))
idx = jnp.argsort(-singular_values)
Copy link
Contributor

Choose a reason for hiding this comment

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

我理解你就只是要把特征值从大到小排序,直接sort就行啊?
singular_values[idx]还会做一次secret index,没有必要

idx = jnp.argsort(-singular_values)
singular_values = singular_values[idx]

return singular_values
Copy link
Contributor

Choose a reason for hiding this comment

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

建议增加一个参数 来指定是否返回特征向量

return A

@jit
def jacobi_svd(A, tol=1e-10, max_iter=5):
Copy link
Contributor

Choose a reason for hiding this comment

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

麻烦增加一些必要的注释信息,起码需要包括:

  1. 明文下原始算法名称(最好包括ref)
  2. (optional)若有与明文算法不同处,可以简单概括并说明一下
  3. 涉及的参数介绍 以及 返回值介绍

print("Start Jacobi SVD emulation.")

def proc_transform(A):
singular_values = jacobi_svd(A)
Copy link
Contributor

Choose a reason for hiding this comment

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

tips:默认配置下,FM64的fxp_bits = 18, 故最小的非0正数为2**-18,如果有稳定性问题,可以试试把tol改大一些?

Copy link
Contributor

Choose a reason for hiding this comment

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

请尽量把算法实现定义在jacobi_svd.py中,在emul文件中仅需要import即可

@deadlywing
Copy link
Contributor

另外,请先sign CLA:
image

复制一下上图红框里的话comment一下即可

@deadlywing
Copy link
Contributor

PLUS: SPU重构了构建系统,python代码的构建推荐使用wrapper函数 spu_py_binary , spu_py_test


n = 10

A_jax = generate_symmetric_matrix(n)
Copy link
Contributor

Choose a reason for hiding this comment

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

这个算法只适用于对称矩阵么?如果是的话也可以直接在docstring里注明一下。。

@BingLiu0
Copy link
Author

I have read the CLA Document and l hereby sign the CLA

@BingLiu0 BingLiu0 closed this by deleting the head repository Feb 24, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants