Skip to content

SFTP Updates #891

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,19 @@ jobs:

- name: Send To Data Team
run: |
# Add to known hosts and create id_rsa file
Copy link
Member

Choose a reason for hiding this comment

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

can you clarify why exactly this is needed and key itself is not enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ayerofieiev-tt without it, it fails with the following error:

/opt/venv/lib/python3.10/site-packages/pysftp/__init__.py:61: UserWarning: Failed to load HostKeys from /github/home/.ssh/known_hosts.  You will need to explicitly load HostKeys (cnopts.hostkeys.load(filename)) or disableHostKey checking (cnopts.hostkeys = None).
  warnings.warn(wmsg, UserWarning)
Traceback (most recent call last):
  File "/__w/pytorch2.0_ttnn/pytorch2.0_ttnn/tools/send_to_data_team.py", line 182, in <module>
    sender.run()
  File "/__w/pytorch2.0_ttnn/pytorch2.0_ttnn/tools/send_to_data_team.py", line 40, in run
    self.send_file(file_path)
  File "/__w/pytorch2.0_ttnn/pytorch2.0_ttnn/tools/send_to_data_team.py", line 51, in send_file
    with pysftp.Connection(
  File "/opt/venv/lib/python3.10/site-packages/pysftp/__init__.py", line 132, in __init__
    self._tconnect['hostkey'] = self._cnopts.get_hostkey(host)
  File "/opt/venv/lib/python3.10/site-packages/pysftp/__init__.py", line 71, in get_hostkey
    raise SSHException("No hostkey for host %s found." % host)
paramiko.ssh_exception.SSHException: No hostkey for host *** found.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ayerofieiev-tt it looks like you changed the title of this PR - but I doubt you did it :) Is this happening automatically?

Screenshot 2025-04-10 at 10 40 54 AM

cc @jmalone-tt

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is happening automatically due to the recent change to PR when generating doc updates. Apologies for the inconvenience, I am working on a change to prevent this from happening

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joelsmithTT @ayerofieiev-tt this is ready for a final review.

A "short" test run with this code succeeded https://github.com/tenstorrent/pytorch2.0_ttnn/actions/runs/14453684858

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mkdir -p ~/.ssh && touch ~/.ssh/known_hosts
ssh-keyscan ${{ secrets.SFTP_OPTEST_HOST }} >> ~/.ssh/known_hosts

rm -rf ~/.ssh/id_rsa
echo "${{ secrets.SFTP_OPTEST_PRIVATE_KEY }}" >> ~/.ssh/id_rsa
chmod 400 ~/.ssh/id_rsa

python3 tools/send_to_data_team.py \
--github_workflow_id ${{ github.run_id }} \
--sftp_host ${{ secrets.SFTP_OPTEST_HOST }} \
--sftp_user ${{ secrets.SFTP_OPTEST_USER }} \
--sftp_private_key ${{ secrets.SFTP_OPTEST_PRIVATE_KEY }}
--sftp_private_key_path ~/.ssh/id_rsa

tests-passed:
if: ${{ always() }}
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tabulate==0.9.0
networkx==3.1
graphviz
matplotlib==3.7.1
pysftp==0.2.9
paramiko==3.5.1

ttnn @ https://github.com/tenstorrent/tt-metal/releases/download/v0.57.0-rc60/ttnn-0.57.0rc60+any-cp38-cp38-linux_x86_64.whl ; python_version=="3.8"
ttnn @ https://github.com/tenstorrent/tt-metal/releases/download/v0.57.0-rc60/ttnn-0.57.0rc60+any-cp310-cp310-linux_x86_64.whl ; python_version=="3.10"
42 changes: 24 additions & 18 deletions tools/send_to_data_team.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import argparse
import pickle
import tempfile
from collections import defaultdict
from datetime import datetime
from pathlib import Path
import paramiko
from typing import List, Dict

import pysftp

from tools.data_collection.pydantic_models import TensorDesc, OpTest


Expand All @@ -17,13 +15,13 @@ def __init__(
github_workflow_id: int,
sftp_host: str,
sftp_user: str,
sftp_private_key: str,
sftp_private_key_path: str,
metrics_directory_name: str = "metrics",
):
self.github_workflow_id = github_workflow_id
self.sftp_host = sftp_host
self.sftp_user = sftp_user
self.sftp_private_key = sftp_private_key
self.sftp_private_key_path = sftp_private_key_path
self.metrics_dir = Path(metrics_directory_name)

def run(self):
Expand All @@ -34,24 +32,32 @@ def run(self):

start_str = str(start).replace(" ", "_").replace(":", "")
file_name = f"pytorch_{start_str}.json"
with tempfile.TemporaryDirectory() as d:
file_path = Path(d) / file_name
self.write_file(pydantic_objects, file_path)
self.send_file(file_path)
folder_path = Path("~/data_team")
folder_path.mkdir(parents=True, exist_ok=True)
file_path = folder_path / file_name

self.write_file(pydantic_objects, file_path)
self.send_file(file_path)

def send_file(self, file_path: Path):
"""
Sends the given file to the data team sftp.
Args:
file_path: Path to the file to send.
"""
with tempfile.NamedTemporaryFile() as private_key_file:
private_key_file.write(bytes(self.sftp_private_key, "utf-8"))
private_key_file.flush()
with pysftp.Connection(
host=self.sftp_host, username=self.sftp_user, private_key=private_key_file.name
) as sftp:
sftp.put(str(file_path))
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy)
ssh.connect(hostname=self.sftp_host, username=self.sftp_user, key_filename=self.sftp_private_key_path)

sftp = ssh.open_sftp()

file_path_str = str(file_path)
sftp.put(file_path_str, file_path_str.split("/")[-1])

sftp.close()
ssh.close()

print(f"Data sent to the Data Team SFTP successfully.")

@staticmethod
def write_file(pydantic_objects: List[OpTest], file_path: Path):
Expand Down Expand Up @@ -168,15 +174,15 @@ def collect_metrics(self, files: Dict[str, List[Path]]) -> List[OpTest]:
parser.add_argument("--github_workflow_id", type=int, help="Github workflow id associated with the run.")
parser.add_argument("--sftp_host", type=str, help="Sftp host.")
parser.add_argument("--sftp_user", type=str, help="Sftp user.")
parser.add_argument("--sftp_private_key", type=str, help="Path to private key.")
parser.add_argument("--sftp_private_key_path", type=str, help="Path to private key.")

args = parser.parse_args()

sender = SendToDataTeam(
github_workflow_id=args.github_workflow_id,
sftp_host=args.sftp_host,
sftp_user=args.sftp_user,
sftp_private_key=args.sftp_private_key,
sftp_private_key_path=args.sftp_private_key_path,
)

sender.run()