Page 1 of 1

Running AI models locally with Ollama

Posted: Mon Jul 29, 2024 8:05 am
by Adrian
If you want to play with AI tools you don't need to give up your privacy and use online tools you can use the latest Llama3 model with Ollama

1. Download and install Ollama https://ollama.com/download (it will crate a half of gig executable in /usr/local/bin/ollama

2. You might need to start ollama "ollama serve & disown" (& to put the service in the background, disown to make sure the service doesn't close when you close that terminal)

3. Download latest llama3 model with "ollama run llama3.1" (this will download about 4.3 GB worth of model to /usr/share/ollama/.ollama) and will crate a terminal prompt where you can ask questions. It's pretty good for programming/troubleshooting tasks, like "create a bash script that goes though each line of a file and compares to the entries in another file and display only the lines that don't match" and the like. Not only that it creates the bash script but it also explains pretty well how it works. Have fun!

Re: Running AI models locally with Ollama

Posted: Mon Jul 29, 2024 9:08 am
by oops
Thanks for sharing ... I will try later (under init systemd and sysvinit).

Code: Select all

$ curl -fsSL https://ollama.com/install.sh | sh
>>> Downloading ollama...
######################################################################## 100,0%##O=#  #                                     ######################################################################## 100,0%
>>> Installing ollama to /usr/local/bin...
[sudo] Mot de passe de tof-mx : 
>>> Creating ollama user...
>>> Adding ollama user to render group...
>>> Adding ollama user to video group...
>>> Adding current user to ollama group...
>>> Creating ollama systemd service...
>>> NVIDIA GPU installed.
>>> The Ollama API is now available at 127.0.0.1:11434.
>>> Install complete. Run "ollama" from the command line.

Re: Running AI models locally with Ollama

Posted: Mon Jul 29, 2024 9:28 am
by Adrian
I added a step two, I think you need to start the "server".

Re: Running AI models locally with Ollama

Posted: Mon Jul 29, 2024 9:38 am
by oops
OK thanks ... I am at 7% of the 4.7GB ... I will try .

Re: Running AI models locally with Ollama

Posted: Mon Jul 29, 2024 9:52 am
by MadMax
This sounds interesting. Thanks for the heads-up.

I'm not much of an AI guy, but it might be a cool thing to try on my VM machine and see how far I can go with 10 years old hardware. It has a dedicated Nvidia GPU, so it might actually be reasonable to run :popcorn:

Re: Running AI models locally with Ollama

Posted: Mon Jul 29, 2024 11:10 am
by oops
Nice, LLaMA speaks french too ;-) ... but for the answer my CPU is about at 100%.

Code: Select all

# to check:
$ ps aux | grep ollama
user-mx   28244  5.1  4.8 29304248 594388 pts/4 Sl   16:01   1:32 ollama serve
user-mx   29642  0.5  0.2 2247280 25444 pts/5   Sl+  16:26   0:01 ollama run llama3
user-mx   29911  0.0  0.0   6708   892 pts/6    S+   16:31   0:00 grep ollama

Code: Select all

$ ollama run llama3
>>> hello
Hello! It's nice to meet you. Is there something I can help you with, or would you like to chat?

>>> Send a message (/? for help)

>>> qui es-tu?
Bonjour!

Je suis LLaMA, un modèle de langage artificiel (AI) développé par Meta AI. Je suis entraîné sur une grande quantité de données pour apprendre à 
comprendre et à générer du texte, comme si j'étais un être humain.

Mon but est de pouvoir répondre à vos questions, discuter avec vous, jouer aux jeux de langage et même créer des contenus amusants. Je suis 
programmé pour être polyglotte, c'est-à-dire que je peux communiquer dans plusieurs langues, y compris le français!

Comment puis-je vous aider aujourd'hui ?


>>> who are you ?
I'm LLaMA, a large language model developed by Meta AI. I was trained on a massive dataset to learn how to understand and generate human-like text.

My purpose is to be able to answer your questions, have conversations with you, play language games, and even create entertaining content. I'm 
designed to be polyglot, meaning I can communicate in multiple languages, including English!

I'm a machine learning model, which means I learn from the data I was trained on and improve over time. My training data includes a vast amount of 
text from various sources, allowing me to understand and respond to a wide range of topics and questions.

So, what would you like to talk about?

>>> Send a message (/? for help)

Code: Select all

>>> quels type d'information peux-tu donner ?
Excellent question !

I can provide information on a wide range of topics, including but not limited to:

1. **General knowledge**: History, science, technology, literature, arts, and more.
2. **Definitions**: I can explain the meaning of words, phrases, and concepts in various fields.
3. **Trivia**: Fun facts, interesting tidbits, and surprising statistics on diverse topics.
4. **Conversational dialogue**: I can engage in natural-sounding conversations, using context to respond to questions and statements.
5. **Language translation**: I can translate text from one language to another (including popular languages like Spanish, French, German, Chinese, 
etc.).
6. **Writing assistance**: I can help with writing tasks, such as suggesting phrases, providing grammar corrections, and offering ideas for creative 
writing.
7. **Jokes and humor**: I have a database of jokes and puns to share, so be prepared for some laughs!
8. **Storytelling**: I can generate short stories, dialogues, or even entire scripts based on prompts or themes.
9. **Personality insights**: I can provide information about personality traits, interests, and characteristics (based on popular frameworks like 
Myers-Briggs).
10. **Education and learning resources**: I can offer study tips, recommend educational content, and help with homework questions.

Remember, my capabilities are constantly evolving as I learn from user interactions and updates to my training data!

What type of information would you like me to provide?

>>> Send a message (/? for help)

Re: Running AI models locally with Ollama

Posted: Mon Jul 29, 2024 11:26 am
by Wirtualny
I guess that having i5-3570S CPU and only an integrated GPU installing Ollama makes no sense. Anyway, it's a very interesting topic. I'm curious about your use cases, and how much time it took on particular configurations.

Re: Running AI models locally with Ollama

Posted: Mon Jul 29, 2024 11:36 am
by oops
Wirtualny wrote: Mon Jul 29, 2024 11:26 am I guess that having i5-3570S CPU and only an integrated GPU installing Ollama makes no sense. Anyway, it's a very interesting topic. I'm curious about your use cases, and how much time it took on particular configurations.
Yes, but It is funny.

Code: Select all

$ inxi -Fxxxraz
System:
  Kernel: 6.1.96-amd64-generic-x86-64-mx19-lru-gen-2024.06.28-18.07
    arch: x86_64 bits: 64 compiler: gcc v: 8.3.0 clocksource: tsc
    avail: hpet,acpi_pm
    parameters: BOOT_IMAGE=/boot/vmlinuz-6.1.96-amd64-generic-x86-64-mx19-lru-gen-2024.06.28-18.07
    root=UUID=69185e50-6110-4a36-bc51-5b15b551ee37 ro lang=fr_FR kbd=fr,us
    kbvar=oss tz=Europe/Paris audit=0 ipv6.disable=1 libata.noacpi=1
    apparmor=0 selinux=0 resume=UUID=13fd7aeb-aa5b-497b-9e6b-a62f362582d0
    zswap.enabled=1 zswap.compressor=zstd zswap.max_pool_percent=35
    zswap.zpool=z3fold quiet
  Desktop: IceWM v: 3.6.0 tools: xautolock,xfce4-screensaver
    avail: i3lock,slock,xscreensaver vt: 7 dm: LightDM v: 1.26.0
    Distro: MX-19.4_x64 patito feo October 21 2019 base: Debian GNU/Linux 10
    (buster)
Machine:
  Type: Desktop Mobo: MSI model: B75MA-E33 (MS-7808) v: 1.0
    serial: <superuser required> uuid: <superuser required>
    UEFI: American Megatrends v: 1.7 date: 09/30/2013
CPU:
  Info: model: Intel Core i5-2320 bits: 64 type: MCP arch: Sandy Bridge
    gen: core 2 level: v2 built: 2010-12 process: Intel 32nm family: 6
    model-id: 0x2A (42) stepping: 7 microcode: 0x2F
  Topology: cpus: 1x cores: 4 smt: <unsupported> cache: L1: 256 KiB
    desc: d-4x32 KiB; i-4x32 KiB L2: 1024 KiB desc: 4x256 KiB L3: 6 MiB
    desc: 1x6 MiB
  Speed (MHz): avg: 1748 high: 2061 min/max: 1600/3300 scaling:
    driver: intel_cpufreq governor: ondemand cores: 1: 1597 2: 2061 3: 1596
    4: 1738 bogomips: 23952
  Flags: avx ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
  Vulnerabilities:
  Type: gather_data_sampling status: Not affected
  Type: itlb_multihit status: KVM: VMX disabled
  Type: l1tf mitigation: PTE Inversion; VMX: conditional cache flushes, SMT
    disabled
  Type: mds mitigation: Clear CPU buffers; SMT disabled
  Type: meltdown mitigation: PTI
  Type: mmio_stale_data status: Unknown: No mitigations
  Type: reg_file_data_sampling status: Not affected
  Type: retbleed status: Not affected
  Type: spec_rstack_overflow status: Not affected
  Type: spec_store_bypass mitigation: Speculative Store Bypass disabled via
    prctl
  Type: spectre_v1 mitigation: usercopy/swapgs barriers and __user pointer
    sanitization
  Type: spectre_v2 mitigation: Retpolines; IBPB: conditional; IBRS_FW;
    STIBP: disabled; RSB filling; PBRSB-eIBRS: Not affected; BHI: Not
    affected
  Type: srbds status: Not affected
  Type: tsx_async_abort status: Not affected
Graphics:
  Device-1: NVIDIA GP107 [GeForce GTX 1050 Ti] driver: nvidia v: 390.157
    non-free: 545.xx+ status: current (as of 2024-06; EOL~2026-12-xx)
    arch: Pascal code: GP10x process: TSMC 16nm built: 2016-2021 pcie: gen: 2
    speed: 5 GT/s lanes: 16 bus-ID: 01:00.0 chip-ID: 10de:1c82 class-ID: 0300
  Display: x11 server: X.Org v: 1.20.10 driver: X: loaded: nvidia
    gpu: nvidia display-ID: :0 screens: 1
  Screen-1: 0 s-res: 1280x1024 s-dpi: 85 s-size: 382x302mm (15.04x11.89")
    s-diag: 487mm (19.17")
  Monitor-1: VGA-0 res: 1280x1024 hz: 60 dpi: 86
    size: 376x301mm (14.8x11.85") diag: 482mm (18.96") modes: N/A
  API: EGL v: 1.4 hw: drv: nvidia platforms: device: egl egl: N/A drv: N/A
    gbm: drv: N/A x11: drv: nvidia inactive: wayland
  API: OpenGL v: 4.6.0 vendor: nvidia v: 390.157 glx-v: 1.4
    direct-render: yes renderer: GeForce GTX 1050 Ti/PCIe/SSE2 memory: 3.91 GiB
  API: Vulkan Message: No Vulkan data available.
Audio:
  Device-1: Intel 7 Series/C216 Family High Definition Audio
    vendor: Micro-Star MSI 7 driver: snd_hda_intel v: kernel bus-ID: 00:1b.0
    chip-ID: 8086:1e20 class-ID: 0403
  Device-2: NVIDIA GF116 High Definition Audio driver: snd_hda_intel
    v: kernel pcie: gen: 2 speed: 5 GT/s lanes: 16 bus-ID: 01:00.1
    chip-ID: 10de:0bee class-ID: 0403
  API: ALSA v: k6.1.96-amd64-generic-x86-64-mx19-lru-gen-2024.06.28-18.07
    status: kernel-api with: 1: aoss type: oss-emulator 2: apulse
    type: pulse-emulator tools: alsactl,alsamixer,amixer
  Server-1: PulseAudio v: 13.0 status: off
    tools: pacat,pactl,pamixer,pavucontrol
Network:
  Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet
    vendor: Micro-Star MSI driver: r8169 v: kernel pcie: gen: 1 speed: 2.5 GT/s
    lanes: 1 port: d000 bus-ID: 03:00.0 chip-ID: 10ec:8168 class-ID: 0200
  IF: eth0 state: up speed: 1000 Mbps duplex: full mac: <filter>
  IF-ID-1: bridge0 state: down mac: <filter>
  IF-ID-2: bridge1 state: down mac: <filter>
  IF-ID-3: virbr0 state: down mac: <filter>
  IF-ID-4: virbr0-nic state: down mac: <filter>
  Info: services: NetworkManager,ntpd,smbd,sshd
Drives:
  Local Storage: total: 1.82 TiB used: 1.15 TiB (63.4%)
  SMART Message: Unable to run smartctl. Root privileges required.
  ID-1: /dev/sda maj-min: 8:0 vendor: Toshiba model: HDWD120 size: 1.82 TiB
    block-size: physical: 4096 B logical: 512 B speed: 3.0 Gb/s tech: HDD
    rpm: 7200 serial: <filter> fw-rev: ACF0 scheme: GPT
Partition:
  ID-1: / raw-size: 29.3 GiB size: 28.67 GiB (97.86%) used: 20.68 GiB (72.1%)
    fs: ext4 dev: /dev/sda4 maj-min: 8:4
  ID-2: /home raw-size: 488.28 GiB size: 479.55 GiB (98.21%)
    used: 361.86 GiB (75.5%) fs: ext4 dev: /dev/sda5 maj-min: 8:5
Swap:
  Kernel: swappiness: 5 (default 60) cache-pressure: 50 (default 100)
    zswap: yes compressor: zstd max-pool: 35%
  ID-1: swap-1 type: partition size: 7.81 GiB used: 3.88 GiB (49.6%)
    priority: -2 dev: /dev/sda6 maj-min: 8:6
Sensors:
  System Temperatures: cpu: 44.0 C mobo: N/A gpu: nvidia temp: 49 C
  Fan Speeds (rpm): N/A gpu: nvidia fan: 32%
Repos:
  Packages: pm: dpkg pkgs: 3177 libs: 1505 tools: apt, apt-get, aptitude,
    deb-get, synaptic pm: rpm pkgs: 0
  No active apt repos in: /etc/apt/sources.list
  No active apt repos in: /etc/apt/sources.list.d/antix-kernel-tmp.list
  Active apt repos in: /etc/apt/sources.list.d/debian-stable-updates.list
    1: deb http://deb.debian.org/debian buster-updates main contrib non-free
  Active apt repos in: /etc/apt/sources.list.d/debian.list
    1: deb http://deb.debian.org/debian buster main contrib non-free
    2: deb http://deb.debian.org/debian-security buster/updates main contrib non-free
  Active apt repos in: /etc/apt/sources.list.d/extended-lts.list
    1: deb http://deb.freexian.com/extended-lts buster-lts main contrib non-free
    2: deb http://deb.freexian.com/extended-lts buster main contrib non-free
  Active apt repos in: /etc/apt/sources.list.d/google-earth-pro.list
    1: deb [arch=amd64] http://dl.google.com/linux/earth/deb/ stable main
  Active apt repos in: /etc/apt/sources.list.d/mozilla.list
    1: deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main
  Active apt repos in: /etc/apt/sources.list.d/mx.list
    1: deb https://mxrepo.com/mx/repo/ buster main non-free
    2: deb https://mxrepo.com/mx/repo/ buster ahs
  No active apt repos in: /etc/apt/sources.list.d/nvidia-drivers.list
  No active apt repos in: /etc/apt/sources.list.d/skype-stable.list
  No active apt repos in: /etc/apt/sources.list.d/thorium.list
  No active apt repos in: /etc/apt/sources.list.d/various.list
Info:
  Memory: total: 12 GiB available: 11.61 GiB used: 4.98 GiB (42.9%)
  Processes: 340 Power: uptime: 7h 5m states: freeze,mem,disk suspend: deep
    avail: s2idle wakeups: 0 hibernate: platform avail: shutdown, reboot,
    suspend, test_resume image: 4.6 GiB services: upowerd,xfce4-power-manager
    Init: SysVinit v: 2.96 runlevel: 5 default: multi-user tool: systemctl
  Compilers: gcc: 8.3.0 Shell: Bash v: 5.0.3 running-in: roxterm
    inxi: 3.3.35

Re: Running AI models locally with Ollama

Posted: Mon Jul 29, 2024 12:01 pm
by Adrian
Seems to be working acceptably fast on my 3 years old desktop that doesn't even have a discrete GPU

Re: Running AI models locally with Ollama

Posted: Mon Jul 29, 2024 12:04 pm
by oops
Adrian wrote: Mon Jul 29, 2024 12:01 pm Seems to be working acceptably fast on my 3 years old desktop that doesn't even have a discrete GPU
Me too. (I have just to wait a bit for the answers and my CPU is at 100% for few seconds)

Re: Running AI models locally with Ollama

Posted: Mon Jul 29, 2024 2:31 pm
by MXRobo
Saw this a few days ago, OS alternatives: https://alternativeto.net/software/olla ... opensource
Not to focus on the O.S. alternatives.

Re: Running AI models locally with Ollama

Posted: Mon Jul 29, 2024 3:12 pm
by MadMax
The installation worked flawlessly for me. Systemd on Debian automatically added, enabled and started the ollama service after installing it. From what I see on the website https://ollama.com/library llama3 is actually an older model. The current one is llama3.1, so I pulled that with ollama run llama3.1.

While downloading it showed the following error a few times, but I just ran the command again and it continued from where it stopped. The server is probably pretty busy at the moment.

Code: Select all

sugomh@hobelstone01:/home/sugomh $ ollama run llama3.1
pulling manifest 
pulling 87048bcd5521...   9% ▕█████                                                        ▏ 437 MB/4.7 GB                  
Error: max retries exceeded: Get "https://dd20bb891979d25aebc8bec07b2b3bbc.r2.cloudflarestorage.com/ollama/docker/registry/v2/blobs/sha256/87/87048bcd55216712ef14c11c2c303728463207b165bf18440b9b84b07ec00f87/data?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=66040c77ac1b787c3af820529859349a%!F(MISSING)20240729%!F(MISSING)auto%!F(MISSING)s3%!F(MISSING)aws4_request&X-Amz-Date=20240729T180049Z&X-Amz-Expires=86400&X-Amz-SignedHeaders=host&X-Amz-Signature=6994740d5d3d9ef57a4fb6d99fe918eca1f71c7149cb7835cc07dc3b6d5c040f": dial tcp: lookup dd20bb891979d25aebc8bec07b2b3bbc.r2.cloudflarestorage.com: no such host
Here on its github page are more instructions what can be done with it: https://github.com/ollama/ollama


These are some relevant specs of my VM machine:

Code: Select all

System:
  Kernel: 6.1.0-23-amd64 arch: x86_64 bits: 64 compiler: gcc v: 12.2.0
    parameters: BOOT_IMAGE=/vmlinuz-6.1.0-23-amd64
    root=UUID=e299bf8d-9fb6-4aba-b16c-f565d691f1d2 ro quiet splash
  Desktop: Xfce v: 4.18.1 tk: Gtk v: 3.24.36 info: xfce4-panel wm: xfwm
    v: 4.18.0 vt: 7 dm: LightDM v: 1.26.0 Distro: Debian GNU/Linux 12 (bookworm)

CPU:
  Info: model: AMD A10-5700 APU with Radeon HD Graphics bits: 64 type: MT MCP
    arch: Piledriver level: v2 built: 2012-13 process: GF 32nm family: 0x15 (21)
    model-id: 0x10 (16) stepping: 1 microcode: 0x6001119
  Topology: cpus: 1x cores: 4 smt: enabled cache: L1: 192 KiB
    desc: d-4x16 KiB; i-2x64 KiB L2: 4 MiB desc: 2x2 MiB
  Speed (MHz): avg: 1400 min/max: 1400/3400 boost: enabled scaling:
    driver: acpi-cpufreq governor: schedutil cores: 1: 1400 2: 1400 3: 1400
    4: 1400 bogomips: 27197

Graphics:
  Device-1: NVIDIA GM107GL [Quadro K2200] vendor: Hewlett-Packard
    driver: nvidia v: 535.183.01 non-free: 530.xx+
    status: current (as of 2023-03) arch: Maxwell code: GMxxx
    process: TSMC 28nm built: 2014-19 pcie: gen: 1 speed: 2.5 GT/s lanes: 16
    link-max: gen: 2 speed: 5 GT/s bus-ID: 01:00.0 chip-ID: 10de:13ba
    class-ID: 0300
  Display: x11 server: X.Org v: 1.21.1.7 compositor: xfwm v: 4.18.0 driver:
    X: loaded: nvidia unloaded: fbdev,modesetting,nouveau,vesa alternate: nv
    gpu: nvidia display-ID: :0.0 screens: 1
  Screen-1: 0 s-res: 2560x1440 s-dpi: 96 s-size: 677x381mm (26.65x15.00")
    s-diag: 777mm (30.58")
  Monitor-1: DP-3 res: 2560x1440 hz: 60 dpi: 109
    size: 597x336mm (23.5x13.23") diag: 685mm (26.97") modes: N/A
  API: OpenGL v: 4.6.0 NVIDIA 535.183.01 renderer: Quadro K2200/PCIe/SSE2
    direct-render: Yes

RAID:
  Supported mdraid levels: raid0 linear multipath raid1 raid6 raid5 raid4
    raid10
  Device-1: md1 maj-min: 9:1 type: mdraid level: raid-0 status: active
    size: 431.89 GiB
  Info: report: N/A blocks: 452866048 chunk-size: 512k super-blocks: 1.2
  Components: Online:
  0: sda2 maj-min: 8:2 size: 216.07 GiB
  1: sdb5 maj-min: 8:21 size: 216.07 GiB

Drives:
  Local Storage: total: raw: 456.46 GiB usable: 456.2 GiB
    used: 261.96 GiB (57.4%)
  SMART Message: Unable to run smartctl. Root privileges required.
  ID-1: /dev/sda maj-min: 8:0 vendor: SanDisk model: Ultra II 240GB
    size: 223.57 GiB block-size: physical: 512 B logical: 512 B speed: 6.0 Gb/s
    type: SSD serial: <filter> rev: 00RL scheme: GPT
  ID-2: /dev/sdb maj-min: 8:16 vendor: Samsung model: SSD 840 Series
    size: 232.89 GiB block-size: physical: 512 B logical: 512 B speed: 6.0 Gb/s
    type: SSD serial: <filter> rev: 8B0Q scheme: GPT

Partition:
  ID-1: / raw-size: 32 GiB size: 31.32 GiB (97.89%) used: 19.89 GiB (63.5%)
    fs: ext4 dev: /dev/md1p1 maj-min: 259:0
  ID-2: /boot raw-size: 1.5 GiB size: 1.44 GiB (96.05%)
    used: 288.1 MiB (19.5%) fs: ext4 dev: /dev/sdb2 maj-min: 8:18
  ID-3: /boot/efi raw-size: 520 MiB size: 519 MiB (99.80%)
    used: 5.8 MiB (1.1%) fs: vfat dev: /dev/sdb1 maj-min: 8:17
  ID-4: /home raw-size: 399.89 GiB size: 398.3 GiB (99.60%)
    used: 120.89 GiB (30.4%) fs: ext4 dev: /dev/md1p2 maj-min: 259:1
    
Swap:
  Kernel: swappiness: 1 (default 60) cache-pressure: 100 (default)
  ID-1: swap-1 type: partition size: 7.5 GiB used: 0 KiB (0.0%) priority: 1
    dev: /dev/sda1 maj-min: 8:1
  ID-2: swap-2 type: partition size: 7.5 GiB used: 0 KiB (0.0%) priority: 1
    dev: /dev/sdb4 maj-min: 8:20

A first test is promising. The generation took about 3-4 minutes and the script works and looks like it's following general bash scripting guidelines. It's interesting to see how the words are generated. Sometimes a full word appears at once, sometimes only a syllable. While generating text my CPU is loaded at about 50-80%, interestingly my GPU is only at about 15%. But its 4 GB of VRAM is maxed out, so VRAM is probably the bottleneck here and the CPU load might come from shuffling data in and out of the VRAM. Regular RAM usage is very low at only a few 100 MBs. So you can definitely run this on not-too-sophisticated hardware.

Code: Select all

sugomh@hobelstone01:/home/sugomh $ ollama run llama3.1
>>> hello, do you speak english?
Hello! Yes, I speak English fluently. How can I help you today?

>>> please write a bash script to rename a list of files in a directory into their sha256 sums. the old filename should be ad
... ded at the end and the directory should be a input variable of the script
Here is a simple bash script that does what you asked for:
```bash
#!/bin/bash

# Check if the directory was provided as an argument
if [ -z "$1" ]; then
  echo "Error: You must provide a directory path as an argument."
  exit 1
fi

# Set the directory variable to the first argument
directory=$1

# Change into the directory
cd "$directory" || { echo "Error: Could not change into directory '$directory'"; exit 1; }

# Loop over each file in the directory
for filename in *; do
  # Skip directories and hidden files
  if [ -d "$filename" ] || [[ $filename == .* ]]; then continue; fi

  # Get the SHA256 sum of the current file
  sha256sum=$(sha256sum "$filename" | cut -d' ' -f1)

  # Rename the file to its SHA256 sum, with the old filename appended at the end
  new_filename="$sha256sum $filename"
  mv "$filename" "$new_filename"

  echo "Renamed '$filename' to '$new_filename'"
done

echo "Finished renaming all files in directory '$directory'"
```
Let me explain how this script works:

1. The first section checks if a directory path was provided as an argument. If not, it prints an error message and 
exits.
2. It sets the `directory` variable to the first argument (the provided directory path).
3. It changes into the specified directory using `cd`.
4. It loops over each file in the directory using a `for` loop.
5. For each file, it checks if it's a directory or hidden file using `[ -d "$filename" ] || [[ $filename == .* ]]`. If 
so, it skips to the next iteration.
6. It gets the SHA256 sum of the current file using `sha256sum`.
7. It renames the file to its SHA256 sum by creating a new filename (`new_filename`) and moving the original file using 
`mv`.
8. Finally, it prints a success message for each renamed file.

You can save this script as a `.sh` file (e.g., `rename_files.sh`) and make it executable with `chmod +x 
rename_files.sh`. Then, you can run it by providing the directory path as an argument, like so: `./rename_files.sh 
/path/to/directory`

Note that this script assumes that all files in the directory are small enough to fit into memory. If you have 
extremely large files, you may need to use a more complex approach that uses temporary files or streaming algorithms to 
compute the SHA256 sum.

Code: Select all

sugomh@hobelstone01:/home/sugomh/test $ ./file_renamer.sh testdir/
Renamed 'FreeFileSync_11.29_Linux.tar.gz' to '1c89cae32098c06262d88a9ab57bdea2703bd5a090668bdde1686c4ff1009d18 FreeFileSync_11.29_Linux.tar.gz'
Renamed 'FreeFileSync_12.5_Linux.tar.gz' to '789f6bdf1431074127f0d17b4a17fb47651a37a41eb31995e46b5915ae6b4507 FreeFileSync_12.5_Linux.tar.gz'
Renamed 'FreeFileSync_13.1_Linux.tar.gz' to '91f5afa7881e2f3725a8ea6f0da4612135a6344be600304f52cb433e20653890 FreeFileSync_13.1_Linux.tar.gz'
Renamed 'FreeFileSync_13.5_Linux.tar.gz' to '90469e9f88d60b0aa2a725c7e4053961d8180b11d726bec63a78e4e7ec137dbe FreeFileSync_13.5_Linux.tar.gz'
Renamed 'FreeFileSync_13.6_Linux.tar.gz' to '0bda846335ab879c7958b1ca5dcdb428a2ea29b5fcae8181fec5e47387712fa0 FreeFileSync_13.6_Linux.tar.gz'
Finished renaming all files in directory 'testdir/'
sugomh@hobelstone01:/home/sugomh/test $ ls -la testdir/
insgesamt 153456
drwxr-xr-x 2 sugomh sugomh     4096 29. Jul 21:09  .
drwxr-xr-x 3 sugomh sugomh     4096 29. Jul 21:08  ..
-rw-r--r-- 1 sugomh sugomh 32478941 10. Mai 17:21 '0bda846335ab879c7958b1ca5dcdb428a2ea29b5fcae8181fec5e47387712fa0 FreeFileSync_13.6_Linux.tar.gz'
-rw-r--r-- 1 sugomh sugomh 30702961 13. Jan 2023  '1c89cae32098c06262d88a9ab57bdea2703bd5a090668bdde1686c4ff1009d18 FreeFileSync_11.29_Linux.tar.gz'
-rw-r--r-- 1 sugomh sugomh 31151584 23. Jul 2023  '789f6bdf1431074127f0d17b4a17fb47651a37a41eb31995e46b5915ae6b4507 FreeFileSync_12.5_Linux.tar.gz'
-rw-r--r-- 1 sugomh sugomh 31611093  5. Apr 18:17 '90469e9f88d60b0aa2a725c7e4053961d8180b11d726bec63a78e4e7ec137dbe FreeFileSync_13.5_Linux.tar.gz'
-rw-r--r-- 1 sugomh sugomh 31177870  7. Nov 2023  '91f5afa7881e2f3725a8ea6f0da4612135a6344be600304f52cb433e20653890 FreeFileSync_13.1_Linux.tar.gz'

Re: Running AI models locally with Ollama

Posted: Mon Jul 29, 2024 3:38 pm
by Adrian
From what I see on the website https://ollama.com/library llama3 is actually an older model. The current one is llama3.1, so I pulled that with ollama run llama3.1.
Ah, thanks, I thought that llamm3:latest would be llama3.1, obviously I was wrong, I will update the instructions on the first page.

Re: Running AI models locally with Ollama

Posted: Mon Jul 29, 2024 3:43 pm
by Adrian
LOL, this is pretty good, better explained than in many places, and it actually made a joke...
>>> if a goat, do you switch the door or not?
I think I see what's happening here!

You're likely referring to the classic Monty Hall problem. The problem states:

Imagine you're on a game show and have the option to choose one of three doors (behind which there is either a
goat or a car). You choose door number 1, for example.

The host now opens one of the other two doors and reveals that it has a goat behind it. Now, the question is:
should you stick with your original choice (door number 1) or switch to the remaining unopened door?

Most people's initial intuition is that it doesn't matter – the probability of either door having the car behind
it is still 1/3.

However, the correct answer is that switching doors gives you a 2/3 chance of winning the car!

Here's why: when you initially chose a door, there was a 1/3 chance the car was behind it and a 2/3 chance the car
was behind one of the other two doors. When the host opens one of those doors and reveals a goat, that eliminates
one of the 2/3 possibilities for the car.

So, you now have a 2/3 chance that the car is behind the remaining unopened door (the one you didn't initially
choose), which makes switching your choice the better option.

Now, in this hypothetical situation where I'm a goat, and we're talking about switching doors... I suppose it's up
to me to decide what happens next! Would you like to stick with your original choice or switch?
>>> switch please
You've decided to switch!

As the host, I'll reveal the other two doors.

Behind door number 2, there's a... goat!

Which means, behind door number 3, which is now your new choice... there's a **CAR**!

Congratulations, you've won the car!

In this hypothetical scenario, switching doors gave you a 2/3 chance of winning the car, and it paid off!

Now, if you'll excuse me, I have to go find my goat friend.

Re: Running AI models locally with Ollama

Posted: Tue Jul 30, 2024 4:56 am
by davidy
I installed ollama a month or so ago and was using one of the neo's from mike adams. I have his latest too. TBQH until we get actual voice to text for pc's having to type is retarded considering the requirements it wants and what it does. I put Futo on my smartphones and it translates my voice easily. Either that or a simple interface that takes the text from your phone and enters it on your pc. I just started using futo fairly recently so I'm not up on all myriad phone aps that might accomplish this. Like use your phone to type into ollama. Typing is waaay too slow. Seriously, the stuff wants it's own supercomputer but it makes you type? Cart before the horse makes it highly impractical.

Re: Running AI models locally with Ollama

Posted: Tue Jul 30, 2024 6:01 am
by Adrian
Yeah, typing is impractical, I heard that Linux kernel has 30 million lines of code... I wonder how they entered those.

Re: Running AI models locally with Ollama

Posted: Tue Jul 30, 2024 10:54 am
by MadMax
Interesting how different opinions can be, isn't it? I for one, dislike all types of voice recognition in tech with a passion :blindfold:

Also remember UNIX philosophy. Do one thing and do it right. No need to cram voice recognition and voice generation in a LLM. They will be built on top of the text-based version via APIs.

Re: Running AI models locally with Ollama

Posted: Tue Jul 30, 2024 1:12 pm
by oops
MadMax wrote: Tue Jul 30, 2024 10:54 am Interesting how different opinions can be, isn't it? I for one, dislike all types of voice recognition in tech with a passion :blindfold:

Also remember UNIX philosophy. Do one thing and do it right. No need to cram voice recognition and voice generation in a LLM. They will be built on top of the text-based version via APIs.
+1

Code: Select all

# to update
$ ollama -v
Warning: could not connect to a running Ollama instance
Warning: client version is 0.3.0

Linux:
    Re-running the install script will download the new version and move it to the right place, it won't re-install any of the other external libraries (like the GPU libraries).
curl https://ollama.ai/install.sh | sh

$ ollama -v
Warning: could not connect to a running Ollama instance
Warning: client version is 0.3.1
A smaller model for PC with few memory and ressources (qwen2:0.5b, gemma2:2b)

Code: Select all

#Google's Gemma 2 has a new 2B parameter small model! (1.6GBytes) --- llama3.1 (4.7GB) 

ollama run gemma2:2b

--update IA models --
ollama pull qwen2:0.5b
ollama pull gemma2:2b

ollama pull llama3.1:8b

$ ollama list
NAME           	ID          	SIZE  	MODIFIED       
qwen2:0.5b      xxxx    352 MB	5 seconds ago 	
llama3.1:8b    	xxxx	4.7 GB	35 minutes ago	
llama3.1:latest xxxx	4.7 GB	35 minutes ago	
gemma2:2b       xxxx	1.6 GB	35 minutes ago


Re: Running AI models locally with Ollama

Posted: Sat Aug 03, 2024 4:57 am
by davidy
Adrian wrote: Tue Jul 30, 2024 6:01 am Yeah, typing is impractical, I heard that Linux kernel has 30 million lines of code... I wonder how they entered those.
When mike adams specifically tells you how to enter/type a question he is obviously not talking in computer code. Back in the 80's I saw the writing on the wall and simply did not want to learn coding ad nauseum which I knew I would be forced to do. Learn one language only for a "better" one to emerge. Didn't want to do it. Hated typing then and now. If there was but a few programming languages to learn I would have entered that field however.

Voice to text already exists on it's own and will not enter a . or a : if you say the words. It cannot translate everything known you can speak. Keyboards on smartphones can translate your voice to text easily without the internet and it makes zero sense to have to type on a pc costing thousands maybe so you can query your supercomputer db on what the best way to treat a cold would be. I am literally the guy who will work smart or not at all. There is way too much stupidity in the workplace already which I'm sure is a main reason why people hate their jobs. When I work with smart people who do things intelligently it makes me happy to do so. There is absolutely no reason, other than the stupidity of google's absurd domination, why there doesn't exist years ago free aps to talk to your own pc that also don't need the internet. The whole purpose of using these llm's is just that. You do not need the internet, ie google. Besides if you are either bilnd or have no hands your voice would come in handy. Cart before the horse.

Re: Running AI models locally with Ollama

Posted: Sat Aug 03, 2024 11:07 am
by Melber
davidy wrote: Sat Aug 03, 2024 4:57 am ..Hated typing then and now...
leaving out the rest of the rant: davidy doesn't like typing. ymmv.

Re: Running AI models locally with Ollama

Posted: Sat Aug 03, 2024 11:47 am
by Adrian
I agree with other posters, voice-to-text input seems to me like a different application, maybe even part of the Desktop Environment. It's also a bit bratty, you get an amazing tool for free and you complains it doesn't come with golden handles.

Re: Running AI models locally with Ollama

Posted: Sat Aug 03, 2024 12:24 pm
by Melber
Handles? Who needs handles? They're so inefficient. All my doors are fitted with motion detectors...

Back on topic. Would be interested in trying this out, but don't think my aged laptop would be able to handle it. Perhaps also scared to confirm I wasted my time learning my very basic bash skills...

Re: Running AI models locally with Ollama

Posted: Sat Aug 03, 2024 2:50 pm
by MadMax
Melber wrote: Sat Aug 03, 2024 12:24 pmPerhaps also scared to confirm I wasted my time learning my very basic bash skills...
You did not. I tried a little more sophisticated script yesterday: the task was to compare a number of random files between two directories to check a random sample for silent corruption - the actual prompt was more specific of course. After a few tries it gave me something what I'd call a "good template". Had to do some work to get it to run and expanded it further since then (added colors to the output, let it count the file size of the checked files implemented a second hash algorithm etc). It didn't work ootb like the simple one before.

BUT I have to admit the template was pretty useful as a starting point. The definition of the input variables and checking for correct inputs was done correctly.

Re: Running AI models locally with Ollama

Posted: Tue Oct 01, 2024 1:05 pm
by Adrian
llama3.2:latest is smaller 2GB and faster if you want to try: "ollama pull llama3.2:latest" and "ollama run llama3.2"

Re: Running AI models locally with Ollama

Posted: Wed Oct 02, 2024 4:23 am
by oops
Adrian wrote: Tue Oct 01, 2024 1:05 pm llama3.2:latest is smaller 2GB and faster if you want to try: "ollama pull llama3.2:latest" and "ollama run llama3.2"
Right, llama3.2:3b (2.0 GB) is faster than llama3.1:8b (4.7 GB), and 8MB of RAM is enough.
( llama3.2:1b (1.3 GB) also exists for PC with only 2 or 4GB)
Thanks for the info:

https://ollama.com/library/llama3.2

Re: Running AI models locally with Ollama

Posted: Tue Dec 24, 2024 11:58 pm
by trawglodyte
It works fine on my 8 yr old machine with an i7-8700 and NVIDIA GTX 1060. The GPU hits 60-70% when the LLM is responding. I tried to add Open WebUI (as instructed in this article --> https://itsfoss.com/ollama-setup-linux/) but was unsuccessful. It does work fine from terminal though, and it's kind of fun that way.

Re: Running AI models locally with Ollama

Posted: Sat Feb 01, 2025 8:12 pm
by trawglodyte
Here is a simple chat GUI for ollama. It assumes you have ollama and at least one LLM installed already, and the ollama server running. You get a dropdown menu to choose between your installed LLMs and a basic chat window. And, yes, AI wrote most of this for me.

Code: Select all

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib
import requests
import threading
import subprocess
import json

# Ollama API endpoint
OLLAMA_API_URL = "http://localhost:11434/api/generate"

class ChatApp(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="Ollama Chat")
        self.set_default_size(900, 600)

        # Main vertical box
        self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
        self.add(self.vbox)

        # Dropdown for model selection
        self.model_store = Gtk.ListStore(str)  # Store model names
        self.model_combo = Gtk.ComboBox.new_with_model(self.model_store)
        renderer = Gtk.CellRendererText()
        self.model_combo.pack_start(renderer, True)
        self.model_combo.add_attribute(renderer, "text", 0)
        self.model_combo.set_active(0)  # Default to the first model
        self.model_combo.connect("changed", self.on_model_changed)
        self.vbox.pack_start(self.model_combo, False, True, 0)

        # Chat history (TextView inside ScrolledWindow)
        self.scrolled_window = Gtk.ScrolledWindow()
        self.scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)  # Vertical scrollbar only
        self.vbox.pack_start(self.scrolled_window, True, True, 0)

        self.chat_history = Gtk.TextView()
        self.chat_history.set_editable(False)
        self.chat_history.set_wrap_mode(Gtk.WrapMode.WORD)
        self.scrolled_window.add(self.chat_history)  # Add TextView to ScrolledWindow

        # Input box (Entry)
        self.input_entry = Gtk.Entry()
        self.input_entry.set_placeholder_text("Type your message here...")
        self.input_entry.connect("activate", self.on_input_activate)
        self.vbox.pack_start(self.input_entry, False, True, 0)

        # Send button
        self.send_button = Gtk.Button(label="Send")
        self.send_button.connect("clicked", self.on_send_clicked)
        self.vbox.pack_start(self.send_button, False, True, 0)

        # Initialize model list and selected model
        self.models = self.get_installed_models()
        self.selected_model = self.models[0] if self.models else None
        self.populate_model_dropdown()

    def get_installed_models(self):
        """Run `ollama list` to get installed models."""
        try:
            result = subprocess.run(["ollama", "list"], capture_output=True, text=True, check=True)
            lines = result.stdout.splitlines()
            models = [line.split()[0] for line in lines[1:]]  # Skip header line
            return models
        except Exception as e:
            print(f"Error fetching models: {e}")
            return []

    def populate_model_dropdown(self):
        """Populate the dropdown with installed models."""
        for model in self.models:
            self.model_store.append([model])
        if self.models:
            self.model_combo.set_active(0)  # Select the first model by default

    def on_model_changed(self, combo):
        """Handle model selection change."""
        tree_iter = combo.get_active_iter()
        if tree_iter is not None:
            model = self.model_store[tree_iter][0]
            self.selected_model = model
            self.append_to_chat_history(f"Switched to model: {model}\n")

    def on_input_activate(self, entry):
        self.send_message()

    def on_send_clicked(self, button):
        self.send_message()

    def send_message(self):
        user_input = self.input_entry.get_text().strip()
        if not user_input:
            return

        # Append user input to chat history
        self.append_to_chat_history(f"You: {user_input}\n")
        self.input_entry.set_text("")  # Clear input box

        # Send request to Ollama in a separate thread
        threading.Thread(target=self.query_ollama, args=(user_input,)).start()

    def query_ollama(self, prompt):
        payload = {
            "model": self.selected_model,
            "prompt": prompt,
            "stream": False
        }

        try:
            response = requests.post(OLLAMA_API_URL, json=payload)
            if response.status_code == 200:
                response_data = response.json()
                response_text = response_data.get("response", "").strip()
                GLib.idle_add(self.append_to_chat_history, f"{self.selected_model}: {response_text}\n\n")
            else:
                GLib.idle_add(self.append_to_chat_history, f"Error: {response.status_code} - {response.text}\n\n")
        except Exception as e:
            GLib.idle_add(self.append_to_chat_history, f"Error: {str(e)}\n\n")

    def append_to_chat_history(self, text):
        buffer = self.chat_history.get_buffer()
        buffer.insert(buffer.get_end_iter(), text)
        # Scroll to the end of the chat history
        self.chat_history.scroll_to_iter(buffer.get_end_iter(), 0, False, 0, 0)

# Run the application
if __name__ == "__main__":
    app = ChatApp()
    app.connect("destroy", Gtk.main_quit)
    app.show_all()
    Gtk.main()

Re: Running AI models locally with Ollama

Posted: Tue Jul 01, 2025 12:48 am
by Bulat
Adrian wrote: Mon Jul 29, 2024 8:05 am If you want to play with AI tools you don't need to give up your privacy and use online tools you can use the latest Llama3 model with Ollama

1. Download and install Ollama https://ollama.com/download (it will crate a half of gig executable in /usr/local/bin/ollama

2. You might need to start ollama "ollama serve & disown" (& to put the service in the background, disown to make sure the service doesn't close when you close that terminal)

3. Download latest llama3 model with "ollama run llama3.1" (this will download about 4.3 GB worth of model to /usr/share/ollama/.ollama) and will crate a terminal prompt where you can ask questions. It's pretty good for programming/troubleshooting tasks, like "create a bash script that goes though each line of a file and compares to the entries in another file and display only the lines that don't match" and the like. Not only that it creates the bash script but it also explains pretty well how it works. Have fun!
Is it possible to download a model (say, llama3) separately, and then run ollama?

Re: Running AI models locally with Ollama

Posted: Tue Jul 01, 2025 6:03 am
by operadude
Adrian wrote: Mon Jul 29, 2024 8:05 am If you want to play with AI tools you don't need to give up your privacy and use online tools you can use the latest Llama3 model with Ollama

1. Download and install Ollama https://ollama.com/download (it will crate a half of gig executable in /usr/local/bin/ollama

2. You might need to start ollama "ollama serve & disown" (& to put the service in the background, disown to make sure the service doesn't close when you close that terminal)

3. Download latest llama3 model with "ollama run llama3.1" (this will download about 4.3 GB worth of model to /usr/share/ollama/.ollama) and will crate a terminal prompt where you can ask questions. It's pretty good for programming/troubleshooting tasks, like "create a bash script that goes though each line of a file and compares to the entries in another file and display only the lines that don't match" and the like. Not only that it creates the bash script but it also explains pretty well how it works. Have fun!
:number1:

Thanks SO much for this :exclamation:

I have been planning to do this for some time, and am now finally ready to give it a spin on a new Testing Rig:

MX-23.6-KDE
Asus H81M-K Desktop (2009 ?):
i5-4690 @ 1.7GHz 64-bit ("Haswell")
8GB RAM (will expand to 16GB, when it arrives)
Nvidia GeForce GT 740 (2GB, v. 418.211.00)
===> tried to update to 418.226.00, but all text and images went to something like 500% (way off the screen), and had to roll-back with the built-in command:

Code: Select all

sudo ddm-mx -p nvidia

Thanks for the detailed instructions, emendations, and follow-up.

Will report back as to how it goes!

:crossfingers:

EDIT/ADDENDUM:

BTW, thanks for the "Monte Hall" problem:

CLASSIC :exclamation:

EDIT/ADDENDUM:

Booted and Updated my Testing Rig (see specs above).
Going through the install steps... :crossfingers: