Jayant-Kernel commited on
Commit
ad9cdcc
·
1 Parent(s): 4838647

fix: patch getpwuid error for HF Spaces

Browse files
Files changed (1) hide show
  1. train.py +20 -1
train.py CHANGED
@@ -1,4 +1,23 @@
1
- import os, sys, json, re, threading, pathlib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from http.server import HTTPServer, BaseHTTPRequestHandler
3
 
4
  os.environ["HF_HOME"] = "/tmp/huggingface"
 
1
+ import os
2
+ import pwd
3
+ import getpass
4
+
5
+ # Fix getpwuid error in HF Spaces
6
+ os.environ["TORCHINDUCTOR_CACHE_DIR"] = "/tmp/torch_cache"
7
+ os.environ["TRITON_CACHE_DIR"] = "/tmp/triton_cache"
8
+ os.makedirs("/tmp/torch_cache", exist_ok=True)
9
+ os.makedirs("/tmp/triton_cache", exist_ok=True)
10
+
11
+ # Patch getpwuid
12
+ try:
13
+ pwd.getpwuid(os.getuid())
14
+ except KeyError:
15
+ import ctypes
16
+ import ctypes.util
17
+ # Override getuser to return a safe default
18
+ getpass.getuser = lambda: "trainer"
19
+
20
+ import sys, json, re, threading, pathlib
21
  from http.server import HTTPServer, BaseHTTPRequestHandler
22
 
23
  os.environ["HF_HOME"] = "/tmp/huggingface"