Hey, I want to set up a local linux server for hosting AI applications (so I could type…
- User
Hey, I want to set up a local linux server for hosting AI applications (so I could type the IP address of that machine + port into my phone browser and write with a language model for example). I have a few questions about it:
-
I want to have a graphical interface for "emergency" uses - because I'm not a linux wizard, I'd like to be able to use a GUI in case things just throw errors over terminal. Would Linux Mint be okay for server use like that?
-
Would I just need to set up SSH? Would I need to log in manually everytime I started that machine, at the machine, just to "access the server"?
-
What are ways to power up/power down such a machine remotely, when connected to ethernet?
-
I'd want to use Hugging Face libraries to load the models - how would I run these things remotely via SSH? Write the necessary scrips in an IDE, then place the Python scripts on the server?
-
How do I make it so it's a "web application" that is being hosted on the server (locally)? Would I just write it into the python script to connect to a specific port (let's say open the port 5002) and listen etc.?
-
What about an interface? I'd like it to function like Oobabooga, if you know that. It's a program that does essentially what I want but inside a single machine. I think it opens a local port, then a web browser tab connected to that local port. Once the site has loaded you're greeted by a Gradio powered interface which interfaces with the inference scripts(?) "below". How could I do something like that? Is this core functionality of Gradio?
Thanks in advance!
-
- Assistant
-
Linux Mint can be used as a server, but it might not be the best choice for performance and stability. Consider using a more server-oriented distribution like Ubuntu Server, CentOS, or Debian. However, if you prefer a graphical interface for occasional use, you can install a lightweight desktop environment on your server.
-
Setting up SSH is essential for remote administration of your server. You would not need to log in manually at the machine each time, as you can access the server remotely via SSH.
-
To power up the machine remotely, you can use the Wake-on-LAN (WoL) feature, which requires enabling it on both the server's BIOS/UEFI and the operating system. To power it down remotely, you can use the
sudo poweroffor commands via SSH.
-
- User
-
Are there lightweight desktop environments that are more catered towards server use? I saw CentOS with a GUI, was that a different version of it?
-
Thanks! Can I write a batch script on my main (Windows) PC to startup the server over WoL and prompt me directly to log in via SSH?
-
What is the difference between "sudo poweroff" and "sudo shutdown"?
-
Nice! Thank you.
-
& 6. Would you recommend Flask? I'd want something that isn't too extremely daunting to learn. Would I need Flask when using Gradio already? Or are they both needed because they do something different?
-
- Assistant
-
There are lightweight desktop environments suitable for server use, such as XFCE, LXDE, and MATE. CentOS with a GUI likely uses GNOME or KDE, which are more resource-intensive. You can install a lightweight desktop environment on your preferred server distribution, such as Ubuntu Server or CentOS.
-
Yes, you can use a batch script or PowerShell script on your Windows PC to send a WoL packet to your server and then open an SSH client (like PuTTY) to connect to the server. For WoL, you may use tools like 'wolcmd' or 'WakeMeOnLan' in your batch script.
-
Both
sudo poweroffandsudo shutdownare used to shut down the system. However,sudo shutdownprovides more options, such as scheduling the shutdown, rebooting the system, or sending a message to all connected users. For example,sudo shutdown -h nowwould immediately halt the system, similar to .
-
- User
- Okay, so I have already prepared a Mint XFCE bootable USB stick for installation - should I switch to something else?
2 & 3. Thank you very much, is there a way to automatically turn off the server a set time after startup? Couldn't I just run "sudo shutdown -h 8" right after logging on via ssh? (Assuming -h stands for hours) Or would that halt any processes and "brick" the system until poweroff?
5 & 6. Thanks! Then I'll look into Gradio and how far I'll get with it standalone. It's just for a personal project/local network for now.
- Assistant
- Linux Mint XFCE is a good choice for a lightweight desktop environment. However, keep in mind that Linux Mint is not designed specifically for server use, which can lead to performance and stability differences compared to server-oriented distributions like Ubuntu Server, CentOS, or Debian. That being said, if you prefer using Linux Mint XFCE, you can still set up your server and applications on it.
2 & 3. Yes, you can schedule an automatic shutdown using the
sudo shutdowncommand. However, the-hflag does not stand for hours; it stands for "halt." To schedule shutdown in 8 hours, you can use:sudo shutdown -h +480This will schedule the system to shutdown in 480 minutes (8 hours). Running the command won't halt any ongoing processes, but when the shutdown is executed, all running processes will be terminated. Be aware that unsaved data may be lost.
5 & 6. Good luck with your Gradio project! It's a great tool for creating simple interfaces for machine learning models, and should work well for a personal project on a local network.
- User
That's super helpful, thanks! One last question: how can I write .bat files that do a certain number of actions on a remote machine via SSH? These things for example:
- Wake on LAN
- log in via SSH (prompt password)
- set shutdown timer
- start gradio project
- Assistant
You can create a batch script on Windows that combines multiple actions using some additional tools. Here's a step-by-step guide:
-
Wake on LAN: You can use the
WakeMeOnLanutility (download here: https://www.nirsoft.net/utils/wake_on_lan.html). Extract theWakeMeOnLan.exeto a directory accessible from the batch script. -
SSH Client: Download the Plink tool, which is a command-line interface to the PuTTY backends (download here: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html). Extract the to a directory accessible from the batch script.
-
- User
Thank you!! That's extremely helpful!
And I have a few more questions still:
What are plink and PuTTY?
And what does WakeMeOnLan.exe do, what would be so hard to do manually?
- Assistant
You're welcome! I'm glad you found the information helpful.
Plink and PuTTY are tools for Windows that help you establish and manage SSH (Secure Shell) connections with remote systems:
- PuTTY: A free and open-source terminal emulator, serial console, and network file transfer application. It supports various network protocols, including SSH, Telnet, rlogin, SCP, and raw socket connections. PuTTY allows you to connect to and manage remote systems using a graphical interface.
- Plink: A companion command-line utility for PuTTY, providing the same SSH functionality as PuTTY without the graphical interface. Plink is useful when you need to automate SSH connections in scripts, like the .bat file we discussed earlier.
WakeMeOnLan.exe is a command-line utility that sends Wake-on-LAN packets to remote systems in your network, causing them to power on if they support WoL. The process of sending these packets needs some specific network settings and packet structures, which WakeMeOnLan conveniently handles for you. It simplifies the task of waking up your remote systems without dealing with low-level network programming.
- User
How would I go about developing the Gradio applciation and the Python functions for inference? I'd want to do it on my main pc (Windows), using Visual Studio Code. But there's this whole thing with dependencies and environments - how can I port it to the Ubuntu Server (decided to go with Ubuntu Server instead of Mint) without it breaking? I think docker would come at a performance cost, no?
- Assistant
Developing your Gradio application and the Python functions for inference can be done on your main Windows PC using Visual Studio Code. To ensure that your code can be reliably transferred and run on the Ubuntu Server, you can use virtual environments.
- User
Absolutely amazing. Can you please also clarify the difference between Anaconda and Miniconda?
- Assistant
Anaconda and Miniconda are both open-source distribution of Python and serve as package managers, providing easy ways to manage Python environments and packages. However, they have some differences in terms of preinstalled packages and size:
Anaconda:
- Anaconda includes a large number of preinstalled packages (over 150) for scientific computing, data analysis, machine learning, and more. These packages are curated to meet the requirements of a wide range of users and use cases.
- It comes with the conda package manager, which allows you to easily create and manage Python environments, install new packages, and update existing ones.
- The distribution is larger in size (~3 GB for the full installation) due to the preinstalled packages.
- User
If I create a new environment using Anaconda, will all the packages be inside? Because there's some specifics with a lot of ML tools, they need specific versions of Python or some package for example and it would kind of a hinderance to have them all "there" if they're the wrong version. Can't be, right? What would the use of environments be, then(?)
- Assistant
When you create a new environment using Anaconda, it doesn't automatically include all of the packages from the base Anaconda distribution. Instead, it starts with a minimal environment with only a few essential packages, like
pipand the specified version of Python. The main purpose of creating an environment is to have an isolated space where you can manage specific packages and their versions without affecting other environments or the base Anaconda distribution.For example, if you create a new conda environment with:
conda create --name my_new_env python=3.8This environment will only have Python 3.8 and a few essential packages installed. You can then install specific packages using the
conda installorpip installcommands as needed in this new environment.To install a specific version of a package, you can use the following command:
conda install package_name=versionFor example:
conda install numpy=1.20.0By using separate environments for different projects, you can manage package dependencies and avoid potential conflicts without affecting your base Anaconda distribution or other projects. Each environment is independent and can have its own versions of Python and packages installed.
- User
I have a question that probably goes way beyong the scope of my little project, but.. what about (multiple) VMs in the context of this local "Gradio web app server"?
- Assistant
Using virtual machines (VMs) can provide another level of isolation and flexibility for your local Gradio web app server project, potentially allowing you to run multiple instances of your server on the same host machine with different configurations or even different operating systems.
- User
Okay, thanks! I think I'll stick with conda environments. And can you tell me some things about the Hugging Face transformers library and PyTorch?
I'm wondering what this line does "model = BertModel.from_pretrained('bert-base-uncased')" - what does it load, a model or the "definition" of an architecture? And does it get these files locally or does it download anything? And if it were to download, does it save things permanently?
Also, this is the full piece of text: "from transformers import BertModel
Load saved model architecture
model = BertModel.from_pretrained('bert-base-uncased')
Load saved model state information
model.load_state_dict(torch.load('path/to/model_state_dict.pt'))
Move model to GPU if available
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') model.to(device)"
Is there something wrong with it? Why is there a torch.load additionally to the HF library's load?
And the last question: Do I need torch's 'cuda' parameter when loading to GPU? I'd like to test things out in the VRAM of an AMD GPU.. could you explain a bit please? Thanks.
- Assistant
I'm happy to help you understand the Hugging Face Transformers library and PyTorch better.
In the given code snippet, the line
model = BertModel.from_pretrained('bert-base-uncased')does the following:- It loads the pre-trained BERT model with the 'bert-base-uncased' architecture.
- By default, it fetches the pre-trained model weights by downloading them from the Hugging Face Model Hub.
When the model is downloaded for the first time, it is cached on your local system, so you won't have to download it again for subsequent uses. The downloaded model files are stored in the directory on your machine.
- User
Thanks! So, the problem is - the server I'm setting up (and where the application will be deployed) will be getting an NVIDIA GPU, but for now it has an AMD GPU and I wanna test deployment on that. My workstation has an NVIDIA GPU.. how can I work around that?
- Assistant
You can develop and test your Gradio web app using the PyTorch CPU execution mode on your local machine, which does not require GPUs. This way, you can develop and test your application without having to worry about GPU compatibility during the development stage.
Update the device selection part in your given code snippet to remove the GPU requirement:
# Don't move the model to GPU device = torch.device('cpu') model.to(device)This change will force the model to run on the CPU, and it should work on any machine regardless of the GPU vendor (NVIDIA or AMD).
When you are ready to deploy the application on the server with the NVIDIA GPU, you can switch back to using:
# Move model to GPU if available device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') model.to(device)This code will automatically use the GPU when it's available (i.e., the server with the NVIDIA GPU) and fall back to using the CPU if no GPU is present, providing a flexible solution for both development and production environments.
- User
Oh yes, thank you very much!
- Assistant
You're welcome! I'm glad I could help. If you have any more questions or need further assistance, please feel free to ask. Good luck with your Gradio web app project and enjoy working with Hugging Face Transformers and PyTorch!
- User
Thanks! Umm, if I wanted to make that web server accessible from the outside (for example so a friend could access the app) - how would I go about protecting myself? I know that network security is a huge, complex field, but just generally. Is there a way to do that for a not-so-experienced dev or should I just keep it local?
- Assistant
You can make your web server accessible from the outside, but it's important to follow some basic security practices to minimize risks. While network security is indeed a complex field, there are some simple steps you can take to protect your server:
-
: Ensure that account passwords on your server are strong and not easily guessable. Avoid using default passwords and change them periodically.
-
- User
Thank you! I think I'll keep it local (for now at least) - out of interest, are there tools that automate "SQL-Injections" (not malicious ones), and so on? What I mean by that is not actual hacking tools, but security testing software that alerts the user if it found a way in? Like a bug-tester for web security.
- Assistant
Yes, there are several security testing tools available that can help you identify vulnerabilities, such as SQL injection or cross-site scripting, in your web applications. These tools can be useful in ensuring the security of your application before deploying it publicly. Some popular security testing tools include:
-
OWASP Zed Attack Proxy (ZAP): ZAP is an open-source web application security scanner developed by the Open Web Application Security Project (OWASP). It can help you automatically identify security vulnerabilities in your web applications during the development phase. ZAP is available for Windows, macOS, and Linux.
-